问题描述
我正在尝试在白色圆圈内填充Bitmap
,更具体地说:
I'm trying to fill Bitmap
inside white circle, more specifically:
例如,我有一个Bitmap
:
我想要这个:
我将背景设为灰色以了解图像.
I've make background gray for understand image.
我使用这种方法,但是不能满足我的要求.
I use this method, but it doesn't make what I want..
public static Bitmap getRoundedBitmap(Bitmap bitmap)
{
final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(output);
final int color = Color.WHITE;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawOval(rectF, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
bitmap.recycle();
return output;
}
推荐答案
我猜您用来绘制椭圆的颜色的ALPHA =0.尝试用Color(1.0f,1.0f,1.0f,1.0替换Color.WHITE F).告诉我这是否解决了您的问题,然后看一下: PorterDuff.Mode在android中是什么意思图形.它有什么作用?
I guess the color you use to paint the oval has ALPHA = 0. Try replacing Color.WHITE with Color(1.0f, 1.0f, 1.0f, 1.0f). Tell me if that solved your problem, and take a look at: What does PorterDuff.Mode mean in android graphics.What does it do?
在这种情况下,对于SRC_IN:[Sa * Da,Sc * Da](摘自android reference,PorterDuff.Mode)
In this case, for SRC_IN: [Sa * Da, Sc * Da] (Taken from android reference, PorterDuff.Mode)
这篇关于白色圆圈内的位图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!