gpt4 book ai didi

android - 如何在位图周围制作发光效果?

转载 作者:IT老高 更新时间:2023-10-28 22:15:06 24 4
gpt4 key购买 nike

以下代码是我目前得到的。但是,有两个问题:

  1. 我想要内部和外部发光效果,看起来类似于 Photoshop 的混合选项。但是我只设法使外部发光,如果我设置 BlurMaskFilter.Blur.INNER 或其他值,则整个图像被阻挡,而不仅仅是边缘。

  2. 尽管我将“FF”设置为 alpha 值,但发光颜色仍然很暗。

    Bitmap alpha = origin.extractAlpha();
    BlurMaskFilter blurMaskFilter = new BlurMaskFilter(5, BlurMaskFilter.Blur.OUTER);

    Paint paint = new Paint();
    paint.setMaskFilter(blurMaskFilter);
    paint.setColor(0xffffffff);

    Canvas canvas = new Canvas(origin);
    canvas.drawBitmap(alpha, 0, 0, paint);

    return origin;

alt text

最佳答案

试试这个,基于 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);


}

关于android - 如何在位图周围制作发光效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4334341/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com