Ask Your Question
0

Getting blank images when trying to construct image using byte array?

asked 2018-06-07 04:58:25 -0600

Ann162 gravatar image

I am using byte array to generate a grayscale png image of size 440*442 size.But all i am getting are blank images of the size.C:\fakepath\FirstMyImgOut.png

byte[] bytesArrayForImage=new byte[array.length];
for (int i=0; i<array.length; i++) {
    bytesArrayForImage[i] = (byte) Integer.parseInt(array[i]);

}
Mat mat = new Mat(440,442, CvType.CV_8UC1);

mat.put(440,442,  bytesArrayForImage);

 String filename111 = Path;
 Highgui.imwrite(filename111, mat);
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-06-07 05:02:15 -0600

berak gravatar image

you have to put the pixels at the start of your image, not at the end. use:

mat.put(0,0,  bytesArrayForImage);
edit flag offensive delete link more

Comments

1

i'd think, it's a bug,that you even can do that (write out of range) !

berak gravatar imageberak ( 2018-06-07 05:05:53 -0600 )edit

i have changed it.but i am still getting same blank images

Ann162 gravatar imageAnn162 ( 2018-06-07 05:10:26 -0600 )edit

then please check, if your bytesArrayForImage has something valid in it.

only to debug it, replace

bytesArrayForImage[i] = (byte) Integer.parseInt(array[i]);

with

bytesArrayForImage[i] = (byte)127;

(that should result in an all gray image at least)

berak gravatar imageberak ( 2018-06-07 05:13:06 -0600 )edit

The generated image has a gray strip on top

Ann162 gravatar imageAnn162 ( 2018-06-07 05:27:54 -0600 )edit

check, if array.length == (440*442)

berak gravatar imageberak ( 2018-06-07 05:44:56 -0600 )edit
1

i checked it is unequal but the initial image of the byte array is of (440*442)size

Ann162 gravatar imageAnn162 ( 2018-06-07 06:18:53 -0600 )edit

well, one error rarely comes alone, as they say.

maybe you can add some code (to your question), showing,where your array comes from.(else it's impossible to say, what happened here)

berak gravatar imageberak ( 2018-06-07 06:57:28 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-07 04:58:25 -0600

Seen: 232 times

Last updated: Jun 07 '18