0
我有一个大多是隐藏的PNG图像,它包含一些水印,我们希望将其应用于另一个图像。黑莓 - 将一个不可见的png位图放置在另一个位置上作为一个新的位图/图像
我已经将这个PNG导入到一个Bitmap对象中。我已经用设备相机导入了第二个图像作为第二个Bitmap对象。
如何叠加PNG位图上方的第二个PNG位图,保留PNG透明度并将结果图像存储为新的位图?
我需要存储结果,因为我将这个最终的位图传递给一个字节数组中的webservice,并将其转换为base64字符串。
我以前使用过这个,但是混合改变了图像的不透明度,这不是我想要的,我希望两个图像都是100%不透明度,以及不可见的PNG ontop ...基本上我想使一帧到一个位图,并存储为一个新的形象:
public static Bitmap blend(Bitmap bi1, Bitmap bi2, double weight)
{
int width = bi1.getWidth();
int height = bi1.getHeight();
Bitmap bi3 = new Bitmap(width, height);
int[] rgbim1 = new int[width];
int[] rgbim2 = new int[width];
int[] rgbim3 = new int[width];
for (int row = 0; row < height; row++)
{
bi1.getARGB(rgbim1,0,width,0,row, width,1);
bi2.getARGB(rgbim2,0,width,0,row, width,1);
for (int col = 0; col < width; col++)
{
int rgb1 = rgbim1[col];
int a1 = (rgb1 >> 24) & 255;
int r1 = (rgb1 >> 16) & 255;
int g1 = (rgb1 >> 8) & 255;
int b1 = rgb1 & 255;
int rgb2 = rgbim2[col];
int a2 = (rgb2 >> 24) & 255;
int r2 = (rgb2 >> 16) & 255;
int g2 = (rgb2 >> 8) & 255;
int b2 = rgb2 & 255;
int a3 = (int) (a1 * weight + a2 * (1.0 - weight));
int r3 = (int) (r1 * weight + r2 * (1.0 - weight));
int g3 = (int) (g1 * weight + g2 * (1.0 - weight));
int b3 = (int) (b1 * weight + b2 * (1.0 - weight));
rgbim3[col] = (a3 << 24) | (r3 << 16) | (g3 << 8) | b3;
}
bi3.setARGB(rgbim3, 0, width, 0, row,width, 1);
}
return bi3;
}
从第一个“位图”创建一个“图形”实例,并在该图形实例上绘制第二个“位图”(透明)。 – Rupak 2012-07-27 04:58:32