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

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -