Buffered image set RGB doesnt work - JAVA -
i have following problem: work image in java. set color pixels , save image. if load image program. pixels having different color ! code:
bufferedimage img = loadimage(); . . //new image drawing bufferedimage newimg = new bufferedimage(img.getwidth(), img.getheight(), bufferedimage.type_int_rgb); graphics2d g2 = (graphics2d) newimg.getgraphics(); //get pixel color int pixel = img.getrgb(0, 0); //parsing color int red = (pixel >> 16) & 0xff; int green = (pixel >> 8) & 0xff; int blue = (pixel) & 0xff; //real drawing g2.setcolor(new color(red, green, blue)); g2.drawline(0, 0, 0, 0); // color r: 55, g: 54 b: 53 //saving imageio.write(newimg, "jpg", outputfile);
after this, run program can read pixel color..
the commands same..
if check color of new image, rgb are: r 52, g: 48 b: 81
.
i set r: 55, g: 53, b:53
, r 52, g: 48 b: 81
where can problem?
thank advice.
this because of jpeg type
jpeg values doesn't save discretely jpeg save rgb values of picture function.
instead of using jpeg use png format , see setrgb() works exactly.
so replace code below
imageio.write(image, "png", outputfile);
Comments
Post a Comment