Wednesday, October 7, 2009

Transpanet Image in J2ME

private static class TransparentImage{
public static Image makeBlend(Image img, int transparent){
int [] rawInt = new int[img.getWidth() * img.getHeight()];
img.getRGB(rawInt, 0, img.getWidth(), 0, 0, img.getWidth(), img.getHeight());
blend(rawInt, transparent);
return Image.createRGBImage(rawInt, img.getWidth(), img.getHeight(), true);
}

public static void blend(int[] raw, int alphaValue, int maskColor, int dontmaskColor){
int len = raw.length;

for(int i=0; i int a = 0;
int color = (raw[i] & 0x00FFFFFF);
if(maskColor==color){
a = 0;
}else if(dontmaskColor==color){
a = 255;
}else if(alphaValue>0){
a = alphaValue;
}

a = (a<<24);
color += a;
raw[i] = color;
}
}
public static void blend(int[] raw, int alphaValue){
blend(raw, alphaValue, 0xFFFFFFFF, 0xFFFFFFFF);
}
}

}

No comments:

Post a Comment