黑莓 - 将一个看不见的png位图放在另一个上面作为新的位图/图像

时间:2012-07-26 12:58:07

标签: blackberry blackberry-simulator blackberry-eclipse-plugin blackberry-jde

我的PNG图像大部分是隐身的,并且包含一些我们想要应用于其他图像的水印。

我已将此PNG导入Bitmap对象。我已将使用设备相机拍摄的第二张图像作为第二个Bitmap对象导入。

如何将PNG位图覆盖在第二个位图上方,保留PNG透明度并将生成的图像存储为新位图?

我需要存储结果,因为我将把这个最终的位图传递给转换为base64字符串的字节数组中的web服务。

我之前使用过这个混合改变了图像的不透明度,这不是我想要的,我希望两个图像都是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;
}

1 个答案:

答案 0 :(得分:0)

您可以通过创建经理来实现此目的。使用经理绘制方法绘制第一张图像&将第二个(水印图像)添加为位图字段。它看起来像图像上的图像。