Saturday 15 August 2015

Parsing Image in Java with different actions for different pixel colours -



Parsing Image in Java with different actions for different pixel colours -

i want colour every black pixel in image color previous pixel had. , if there 2 or more consecutive black pixels, colour of lastly non-black pixel taken. figured out how iterate through pixels pixels won't alter colour. think miss "save changes" line.

here code:

public static void iteratepixels() throws ioexception { file file = new file("c:\\blackdots.png"); bufferedimage image = imageio.read(file); int lastnotblack = -1; int actualcolour = 0; (int x = 0; x < image.getheight(); x++) { (int y = 0; y < image.getwidth(); y++) { int black = -16777216; seek { actualcolour = image.getrgb(x, y); } grab (exception e) { continue; } if(image.getrgb(x, y)==black){ image.setrgb(x, y, lastnotblack); system.out.println("black pixel at: " +x +" "+y); } if (actualcolour != black){ lastnotblack= actualcolour; } } } }

so how appy changes ? or there mistake?

you're changing pixels in in-memory image, need write pixels file:

imageio.write(image, "png", new file("c:\\blackdots_modified.png"));

(to called after pixels have been modified)

also see: https://docs.oracle.com/javase/tutorial/2d/images/saveimage.html

java image pixel javax.imageio

No comments:

Post a Comment