How to make glow effect around a bitmap?

后端 未结 6 1167
盖世英雄少女心
盖世英雄少女心 2020-12-23 10:35

The following code is what I got so far. However, there are 2 issues:

  1. I want both inner and outer glow effects, which look similar to the Photoshop\'s blend

6条回答
  •  一向
    一向 (楼主)
    2020-12-23 10:55

    Try this, based on XGouchet's answer.

    private void setBackgroundGlow(ImageView imgview, int imageicon,int r,int g,int b)
    {
        // An added margin to the initial image
        int margin = 24;
        int halfMargin = margin / 2;
        // the glow radius
        int glowRadius = 40;
    
        // the glow color
        int glowColor = Color.rgb(r, g, b);
    
        // The original image to use
        Bitmap src = BitmapFactory.decodeResource(getResources(),imageicon);
    
        // extract the alpha from the source image
        Bitmap alpha = src.extractAlpha();
    
        // The output bitmap (with the icon + glow)
        Bitmap bmp =  Bitmap.createBitmap(src.getWidth() + margin, src.getHeight() + margin, Bitmap.Config.ARGB_8888);
    
        // The canvas to paint on the image
        Canvas canvas = new Canvas(bmp);
    
        Paint paint = new Paint();
        paint.setColor(glowColor);
    
        // outer glow
        paint.setMaskFilter(new BlurMaskFilter(glowRadius, Blur.OUTER));//For Inner glow set Blur.INNER
        canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);
    
        // original icon
        canvas.drawBitmap(src, halfMargin, halfMargin, null);
    
        imgview.setImageBitmap(bmp);
    
    
    }
    

提交回复
热议问题