AffineTransform is not enough. It does not process Alpha or transparence 透明.
I used raster to do this.
If the image (.gif) has alpha channel, transform only pixels which alpha !=0.
If the image (.jpg) has no alpha channel, it become a little more complex. If I know the image has white( or other) background, the only transfor pixels are not white.
Process:
Image src=..... //width,height
BufferedImage proc= new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
Graphics2D g2=proc.createGraphics();
g2.drawImage(src,width,height,null); //offscreen copy src to proc
float[][] matrix={ //alpha blend: src*0.75+dst*0.25, dst is a blue rect
{0.75f,0,0,0,0}, //red
{0,0.75f,0,0,0}, //green
{0,0,0.75f,0,255*0.25f}, //blue, increase blue channel
{0,0,0,0.75f,255*0.25f} //alpha
}
BandCombineOp op=new BandCombineOp(matrix, null){
// override filter to process alpha channel
public WritableRaster filter(Raster src,
WritableRaster dst){
...//src.getPixel
...//getAlpha
...//if has alpha channel and alpha!=0 use matrix to transfor
...//if no ahpha channel, and pixel color is not the background,
//do transform
.. //dst.setPixel
return dst;
}
}
WritableRaster rDst=op.filter(rSrc,rSrc); //op.filter(rSrc,null) is the same
BufferedImage dst=new BufferedImage(cm, rDst,false,null);
//draw dst to the screen if selected.
1.op.filter() refer to j2sdk source code, add the code to process alpha
2.adjust 0.75f to other numbers to get the effect you want.