public void drawBlendedImage(Image bottom, Image top, Graphics g,  
int coeff, int x, int y) 
{ 
   // Zarezerwowanie tablicy pikseli danych dla kadego obrazu. 
   int [] bottomData = new int[bottom.getHeight()*bottom.getWidth()]; 
   int [] topData = new int[top.getHeight()*top.getWidth()];

   // Pobranie poszczeglnych pikseli kadego obrazu (rdo, maska).
   bottom.getRGB(bottomData, 0, bottom.getWidth(), 0, 0, bottom.getWidth(), 
   bottom.getHeight()); 
   top.getRGB(topData, 0, top.getWidth(), 0, 0, top.getWidth(), top.getHeight()); 

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

   // Iteracja przez wszystkie piksele obrazw: grnego i dolnego. 
   for (int i=0;i<bottomData.length;i++) { 
      // Pobranie wartoci poszczeglnych kanaw dla kadego piksela (gra, 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); 

      // Uycie wzoru mieszania obrazw.
      resultA = ( alpha1 * coeff + alpha2 * (255 - coeff) ) / 255; 
      resultR = ( red1 * coeff + red2 * (255 - coeff) ) / 255; 
      resultG = ( green1 * coeff + green2 * (255 - coeff) ) / 255; 
      resultB = ( blue1 * coeff + blue2 * (255 - coeff) ) / 255; 

      // Utworzenie ostatecznej wartoci piksela. 
      bottomData[i] = resultA << 24 | resultR << 16 | resultG << 8 | resultB ; 
   } 
   // Wywietlenie wygenerowanego obrazu. 
   g.drawRGB(bottomData, 0, bottom.getWidth(), x, y, bottom.getWidth(), 
   bottom.getHeight(), true); 
}
