0

J'ai une image PNG qui est la plupart du temps invisble et contient quelques filigranes nous à appliquer à une autre image.Blackberry - Placez un bitmap invisible .png ci-dessus l'autre comme une nouvelle Bitmap/Image

J'ai importé ce PNG dans un objet Bitmap. J'ai importé la deuxième image, prise avec la caméra de l'appareil, en tant que second objet Bitmap.

Comment puis-je recouvrir le bitmap PNG au-dessus du second, en conservant la transparance PNG et stocker l'image résultante en tant que nouvelle image?

J'ai besoin de stocker les résultats que je passerai cette image bitmap finale à un webservice dans un tableau d'octets converti en une chaîne base64. Je l'ai utilisé avant mais le mélange change l'opacité des images, ce n'est pas ce que je veux, je veux que les deux images soient pleines à 100% d'opacité, avec l'invisble PNG ontop ... fondamentalement je veux faire un cadre sur une image bitmap et stocker que comme une nouvelle image .:

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

créer une instance 'Graphics' de la première' Bitmap', et sur cette instance 'Graphics' peindre la seconde' Bitmap' (une transparent). – Rupak

Répondre

0

Vous pouvez y parvenir en créant un gestionnaire. Dessiner la première image à l'aide des gestionnaires de peinture méthode & ajouter seconde (image filigrane) pour comme un Bitmap champ. Cela ressemblera à l'image sur l'image.

Questions connexes