java - Printing two images in one -



java - Printing two images in one -

i'm new java , have problem code. first part works perfectly, gets rgb values of every pixel of input image, multiplies values specific number , saves result new image.

try { file input = new file("obr4.png"); image2 = imageio.read(input); int width = image2.getwidth(); int height = image2.getheight(); (int = 0; < height; i++) { (int j = 0; j < width; j++) { color c = new color(image2.getrgb(j, i)); int reddish = (int) (c.getred() * math.abs(text2value)); if (red > 255) { reddish = 255; } int greenish = (int) (c.getgreen() * math.abs(text2value)); if (green > 255) { greenish = 255; } int bluish = (int) (c.getblue() * math.abs(text2value)); if (blue > 255) { bluish = 255; } color newcolor = new color(red, green, blue); image2.setrgb(j, i, newcolor.getrgb()); //system.out.println("row: "+i+" column: "+j+" red: "+red+" green: "+green+" blue: "+blue); } } file output2 = new file("grayscale2.jpg"); imageio.write(image2, "jpg", output2); repaint(); } grab (exception e2) { system.out.println("error"); }

same code different values works sec image.

now tricky part: want 2 new created images set in 1 image - pixel values form pic1 , pic2, add together them , print result. far have code:

try { file input1 = new file("grayscale1.jpg"); file input2 = new file("grayscale2.jpg"); finalimage1 = imageio.read(input1); finalimage2 = imageio.read(input2); (int = 0; < 256; i++) { (int j = 0; j < 256; j++) { color c = new color(finalimage1.getrgb(j, i)); int red1 = (int) (c.getred()); int green1 = (int) (c.getgreen()); int blue1 = (int) (c.getblue()); color o = new color(finalimage2.getrgb(j, i)); int red2 = (int) (o.getred()); int green2 = (int) (o.getgreen()); int blue2 = (int) (o.getblue()); int reddish = (red1 + red2) / 2; if (red > 255) { reddish = 255; } int greenish = (green1 + green2) / 2; if (green > 255) { greenish = 255; } int bluish = (blue1 + blue2) / 2; if (blue > 255) { bluish = 255; } color newcolor = new color(red, green, blue); finalimage.setrgb(j, i, newcolor.getrgb()); // system.out.println("row: "+i+" column: "+j+" red: "+red+" green: "+green+" blue: "+blue); } } file output = new file("finalimage.jpg"); imageio.write(finalimage, "jpg", output); } grab (exception e) { system.out.println("sum error"); }

it should work same previous codes, doesn't. gives "sum error". problem seems somewhere in creating finalimage, because if print values console seems right. please, if have idea, wrong, allow me know. give thanks you

java image rgb

Comments

Popular posts from this blog

php - Edges appear in image after resizing -

ios8 - iOS custom keyboard - preserve state between appearances -

Delphi change the assembly code of a running process -