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

從第一個「位圖」創建一個「圖形」實例,並在該圖形實例上繪製第二個「位圖」(透明)。 – Rupak 2012-07-27 04:58:32

回答

0

您可以通過創建一個管理者做到這一點。使用管理器畫圖方法繪製第一個圖像&將第二個圖像(水印圖像)添加到位圖字段中。它看起來像是圖像上的圖像。

相關問題