Hon*_*gbo 25 graphics android bitmap glow
以下代码是我到目前为止所得到的.但是,有两个问题:
我想要内部和外部发光效果,看起来类似于Photoshop的混合选项.但我只设法制作外部发光,如果我设置BlurMaskFilter.Blur.INNER或其他值,整个图像被阻挡,而不是只是边缘.
尽管我将" 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;
Run Code Online (Sandbox Code Playgroud)
小智 5
根据XGouchet的答案尝试此操作。
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);
}
Run Code Online (Sandbox Code Playgroud)
我认为android中没有方法可以创建发光效果。你必须自己从头开始制作它们,或者找到一些支持它的java库。
我更喜欢使用的最简单的方法是制作图像层。基本上你定义了一个相对布局并将 2 个 imageView 一个放在另一个之上。只需在其自己的图层中创建 Photoshop 效果并对该图层进行光栅化,将其保存为 png 并将其放在图像的顶部。但要小心,如果您对大图像使用此方法,您很容易出现 VM 超出异常。根据视图大小对位图重新采样是解决此问题的一个很好的解决方案。
我想到的另一种方法是在图像上绘制渐变(例如:中间透明、边缘白色的径向渐变,以获得白色光芒),但这种方法需要很多时间才能准确调整你需要什么,所以在我看来不值得付出努力)。
这里还有一个制作 java 图像过滤器的网站的链接。也许你可以找到适合你的东西。
http://www.jhlabs.com/ip/filters/index.html
| 归档时间: |
|
| 查看次数: |
23870 次 |
| 最近记录: |