CODE:
public final void SetBitmapImage(Bitmap paramBitmap, int color, float percentage)
{
float f = percentage * -360.0F;
int i = paramBitmap.getWidth();
int j = paramBitmap.getHeight();
Paint localPaint1 = new Paint(ANTI_ALIAS_FLAG);
Paint localPaint2 = new Paint(ANTI_ALIAS_FLAG);
Paint localPaint3 = new Paint(ANTI_ALIAS_FLAG);
Bitmap localBitmap1 = Bitmap.createBitmap(i, j, Bitmap.Config.ARGB_8888);
Canvas localCanvas1 = new Canvas(localBitmap1);
localCanvas1.rotate(-90.0F, i / 2.0F, j / 2.0F);
RectF localRectF = new RectF(0.0F, 0.0F, i, j);
localPaint1.setStrokeWidth(2.0F);
localPaint1.setStyle(Paint.Style.FILL);
localPaint2.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
Bitmap localBitmap2 = paramBitmap; // this should include color I think but don't know how
localCanvas1.drawArc(localRectF, 0.0F, f, true, localPaint1);
Bitmap localBitmap3 = Bitmap.createBitmap(localBitmap1.getWidth(), localBitmap1.getHeight(), Bitmap.Config.ARGB_8888);
Canvas localCanvas2 = new Canvas(localBitmap3);
localCanvas2.drawBitmap(paramBitmap, 0.0F, 0.0F, localPaint3);
localCanvas2.drawBitmap(localBitmap1, 0.0F, 0.0F, localPaint2);
Bitmap localBitmap4 = Bitmap.createBitmap(localBitmap2.getWidth(), localBitmap2.getHeight(), localBitmap2.getConfig());
Canvas localCanvas3 = new Canvas(localBitmap4);
localCanvas3.drawBitmap(localBitmap2, new Matrix(), null);
localCanvas3.drawBitmap(localBitmap3, 0.0F, 0.0F, null);
localBitmap2.recycle();
localBitmap3.recycle();
localBitmap1.recycle();
setImageBitmap(localBitmap4);
}
但图像仍然相同。我希望70%的图像保持白色,30%红色。
我认为问题出在Bitmap localBitmap2
。
Bitmap localBitmap2 = paramBitmap; // this should include color I think but don't know how
应该是这样的:
Bitmap localBitmap2 = Something(paramBitmap, color); which will set the color
答案 0 :(得分:1)
在android中,当你设置一个十六进制代码时,#后面的前6位是普通代码,并且透明后有一个可选的2位数字。
#000000 = black
#00000000 = fully transparent
鉴于最后两位数字必须是十六进制格式,您需要选择0到255之间的范围,然后将其转换回十六进制。
提示:您可以使用程序员中的Windows计算器来完成此操作。模式。 :)
示例:
30%不透明度:255 * 0.70 = 178. 178转换为十六进制= B2。
因此,将B2添加到您拥有的任何颜色代码的末尾,它将是30%不透明。
#000000B2
希望这有帮助。