| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 
 |  
newComposite = AlphaComposite.getInstance(AlphaComposite.SRC);
newComposite2 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER);
 
buffer_REFERENCE = ipC_Map.getBufferedImage();
 
bufferINPUT = ipC_INPUT.getBufferedImage();
 
buffer = new bufferedImage(buffer_REFERENCE.getWidth(),buffer_REFERENCE.getHeight(),BufferedImage.TYPE_INT_ARGB_PRE);
 
bufferINPUT_Mask = new BufferedImage(bufferINPUT.getWidth(),bufferINPUT.getHeight(),BufferedImage.TYPE_INT_ARGB_PRE);
 
	graphicsBufferINPUT = bufferINPUT_Mask.createGraphics();
 
	graphicsBufferINPUT.setComposite(newComposite);
	graphicsBufferINPUT.drawImage(bufferREFERENCE,0, 0,null);
 
	graphicsBufferINPUT.dispose();
 
	// calcul la composante alpha qui est le niveau de gris de l'image.
    	pixel = 0;
	alpha = 0;
 
	for (int x = 0; x < bufferINPUT.getWidth(); x++) {
		for (int y = 0; y < bufferINPUT.getHeight(); y++) {
 
			pixel = bufferINPUT_Mask.getRGB(x, y);
 
			//Transform to grey level
			alpha = ( ((pixel & 0xff0000) >> 16) + ((pixel & 0xff00) >> 8) + (pixel & 0xff)) / 3;
			//Add alpha to the color
			pixel = alpha << 24 | (pixel & 0xff0000) >> 16 << 16 | (pixel & 0xff00) >> 8 << 8 | pixel & 0xff;
 
			bufferINPUT_Mask.setRGB(x, y, pixel);
			}
		}
 
		//Create the graphics2D object of buffer 
		graphicsBuffer = buffer.createGraphics();
 
		graphicsBuffer.drawImage(buffer_REFERENCE,0, 0,null);
 
		graphicsBuffer.setComposite(newComposite2);
 
		graphicsBuffer.drawImage(bufferINPUT_Mask, 0,0, null);
		graphicsBuffer.dispose(); | 
Partager