【问题标题】:Blackberry - Place one invisible png bitmap above another as a new Bitmap/ImageBlackberry - 将一个不可见的 png 位图放在另一个上方作为新的位图/图像
【发布时间】:2012-07-30 23:40:57
【问题描述】:

我有一个大部分是不可见的 PNG 图像,并且包含一些我们想要应用到另一个图像的水印。

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

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

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

我以前用过这个,但是混合会改变图像的不透明度,这不是我想要的,我希望两个图像都是完全 100% 的不透明度,顶部是不可见的 PNG...基本上我想做一个帧到位图上并将其存储为新图像。:

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;
}

【问题讨论】:

  • 从第一个Bitmap 创建一个Graphics 实例,然后在该Graphics 实例上绘制第二个Bitmap(透明的)。

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-24
    • 2021-11-26
    • 1970-01-01
    相关资源
    最近更新 更多