java - How to get rid of a color in an image -


i want image, buffered image, have transparent background, first tries using png, gif, tried using imagefilters not hit off, decided use simple jpeg, set background color , rid of color, again, assume imagefilters fit that, don't know how use them, color want rid of 0xff00d8 (magenta).

can way this, or example?

jpeg doesn't support transparency. make sure buffered image supports transparency:

bufferedimage bi = new bufferedimage(w, h, bufferedimage.type_int_argb); 

the in type_int_argb stands alpha measure of opacity.

you need set pixel value 0x00000000 in order make transparent.

//load image bufferedimage in = imageio.read(img); int width = in.getwidth(), height = in.getheight(); bufferedimage bi = new bufferedimage(width, height, bufferedimage.type_int_argb); graphics2d g = bi.creategraphics(); g.drawimage(in, 0, 0, null); g.dispose();  //change color int colortochange = 0xff00d8; (int x=0;x<width;x++)     (int y=0;y<height;y++)         if(bi.getrgb(x,y)==colortochange)             bi.setrgb(x,y,0x00ffffff&colortochange);  bi.save(new file("out.png")); 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -