public void drawMultipliedImage(Image firstImage, Image secondImage,  
Graphics g, int x, int y) 
{ 
   // Zarezerwowanie tablicy pikseli danych dla każdego obrazu.
   int [] bottomData = new int[firstImage.getHeight()*firstImage.getWidth()]; 
   int [] topData = new int[secondImage.getHeight()*secondImage.getWidth()]; 
   
   // Pobranie poszczególnych pikseli każdego obrazu (źródło, maska). 
   firstImage.getRGB(bottomData, 0, firstImage.getWidth(), 0, 0,  
   firstImage.getWidth(), firstImage.getHeight()); 
   secondImage.getRGB(topData, 0, secondImage.getWidth(), 0, 0,  
   secondImage.getWidth(), secondImage.getHeight()); 

   // Zdefiniowanie wymaganych wartości piksela. 
   int alpha1, alpha2; 
   int red1, red2; 
   int green1, green2; 
   int blue1, blue2; 
   int resultA,resultR,resultG,resultB; 

   for (int i=0;i<bottomData.length;i++) { 
      // Pobranie wartości poszczególnych kanałów dla każdego piksela (góra, dół).
      alpha1 = (bottomData[i] & 0xFF000000) >>> 24; 
      alpha2 = (topData[i] & 0xFF000000) >>> 24; 
      red1 = (bottomData[i] & 0x00FF0000) >> 16; 
      red2 = (topData[i] & 0x00FF0000) >> 16; 
      green1 = (bottomData[i] & 0x0000FF00) >> 8; 
      green2 = (topData[i] & 0x0000FF00) >> 8; 
      blue1 = (bottomData[i] & 0x000000FF); 
      blue2 = (topData[i] & 0x000000FF); 
      resultA = alpha1 * alpha2 / 255 ; 
      resultR = red1 * red2 / 255 ; 
      resultG = green1 * green2 / 255 ; 
      resultB = blue1 * blue2 / 255; 
      // Utworzenie ostatecznej wartości piksela. 
      bottomData[i] = resultA << 24 | resultR << 16 | resultG << 8 | resultB ; 
   } 
   // Wyświetlenie wygenerowanego obrazu.
   g.drawRGB(bottomData, 0, firstImage.getWidth(), x, y, firstImage.getWidth(), 
   firstImage.getHeight(), true); 
} 
