hello, i'm new to this forum, i hope to find some answers
my problem is that i have a .png file, and i read the content to a BufferedImage object, then i move that into a
pixel array, the file is a picture of characters that need to be in the game, the problem is that when i paint them,
i can see their background from the file and not the background of the game, i am looking for help as to how to
make the background transparent. i have looked over the web for solutions, but things just won't work,
i have managed to set the Alpha number of the specific color to zero. but still i see in the game panel the gray
color of java's usual background, here is the code:
// target - the image, rgba - the color to kill. public void cleanImage(BufferedImage target,int r,int g,int b,int a) { int col = ((a << 24) | (r << 16) | (g << 8) | b); int trans = ((0 << 24) | (r << 16) | (g << 8) | b); int [] pixels = ((DataBufferInt)target.getRaster().getDataBuffer()).getData(); ColorModel cm = target.getColorModel(); SampleModel sm = target.getRaster().getSampleModel(); for (int i = 0;i<pixels.length;i++) if (pixels[i] == col) pixels[i] = trans;//-1118482; DataBuffer db = new DataBufferInt(pixels,target.getHeight()*target.getWidth()); WritableRaster wr = Raster.createWritableRaster(sm,db,null); target = new BufferedImage(cm, wr, false, null); }