如何在Android中围绕图像制作发光效果?

时间:2020-09-18 04:23:08

标签: java android android-imageview

我对如何在图像周围创建发光效果进行了很多研究,如下图所示

图片:

enter image description here

我的代码:

ImageView imageView = ((ImageView) findViewById(R.id.bmpImg))
 // An added margin to the initial image
int margin = 24;
int halfMargin = margin / 2;
// the glow radius
int glowRadius = 16;
// the glow color
int glowColor = Color.rgb(0, 192, 255);
// The original image to use
Bitmap src = BitmapFactory.decodeResource(getResources(),
 R.drawable.myImg);
// 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));
canvas.drawBitmap(alpha, halfMargin, halfMargin, paint);
// original icon
canvas.drawBitmap(src, halfMargin, halfMargin, null);
imageView.setImageBitmap(bmp);

但是我没有任何效果。

任何有创意的人!

0 个答案:

没有答案
相关问题