0

我正在开发一个 android 应用程序,我需要在其中捕获文本并将其保存为透明图像。捕获文本已经完成,但是制作一个透明的 png 文件是我卡住的地方,因为我根本不熟悉图像像素操作。这是我到目前为止所拥有的......我首先创建一个空白位图并用白色背景填充它,然后我将油漆的透明度设置为 0(完全透明),然后使用 XOR 模式将源位图绘制到目标位图中。 . 但是当我运行应用程序时,我看到的只是一张空白的白色图像。如果有人指出我做错了什么以及如何解决它,我会很高兴。提前致谢。

b = Bitmap.createBitmap(tw, th,Bitmap.Config.ARGB_8888); 
Canvas canvas = new Canvas(b);
Rect dest = new Rect(0,0,b.getWidth(),b.getHeight());               
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.WHITE);

canvas.drawRect(0, 0, b.getWidth(), b.getHeight(), paint);
paint.setAlpha(0);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));
canvas.drawBitmap(bmp,null,dest,paint);
4

2 回答 2

1

Have you looked at : How to change a bitmap's opacity? Seems like

paint.setAlpha(0);

won't do anything as you need to set the alpha channel to something greater than 0...

于 2012-04-04T03:14:10.257 回答
0

Use:

Color.argb(0,0,0,0)

The first parameter is the alpha. Set it to 0 for complete transparency.

于 2012-04-04T03:21:17.253 回答