java - Not able to generate same output image from source input -


i reading .jpg file integer array(source) , trying generate new image same data, code producing black image. should produce duplicate image source.

        string srcname = "input.jpg";         file srcfile = new file(srcname);         bufferedimage image = imageio.read(srcfile);         system.out.println("source image: " + srcname);           int w = image.getwidth();         int h = image.getheight();         int[] src = image.getrgb(0, 0, w, h, null, 0, w);          system.out.println("array size " + src.length);           bufferedimage dstimage = new bufferedimage(w, h, bufferedimage.type_int_argb);         // generating destination image same source array         dstimage.setrgb(0, 0, w, h, src, 0, w);          string dstname = "output.jpg";         file dstfile = new file(dstname);         imageio.write(dstimage, "jpg", dstfile);         system.out.println("output image: " + dstname); 

you need use same color encoding type both images. input image not encoded bufferedimage.type_int_argb.

this fixed test image, had type bufferedimage.type_3byte_bgr:

bufferedimage dstimage = new bufferedimage(w, h, image.gettype()); 

however, wouldn't expect newly written image same input. i'd rather expect imageio introduce artifacts while encoding image data jpg.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -