loading
 
SetImage - ArrayOut of bound exception
Abhishek Verma from India  [6 posts]
10 years
HI Friends,
I am having a problem in using setImage(String,byte[],length,height).

I am using java. and i am getting array out of bound exception when i am tring to write pixel array length=786432, w = 1024, h = 768.
Below is the exception thrown.

Pixel lenghth 786432w = 1024, h = 768
Exception in thread "Thread-1" java.lang.ArrayIndexOutOfBoundsException
    at java.net.SocketOutputStream.socketWrite(Unknown Source)
    at java.net.SocketOutputStream.write(Unknown Source)
    at java.io.BufferedOutputStream.write(Unknown Source)
    at ibaux.image.analysis.roborealm.RoboRealmAPI.setImage(RoboRealmAPI.java:415)
    at ibaux.watch.watcher.Watcher.run(Watcher.java:33)


Please help me in finding out the cause..

Thanks in advance
Abhishek
Anonymous 10 years
Abhishek,

Based on your information it looks like you are missing 2/3 of the image. The pixel length should be 1024*768*3 instead of just 1024*768. The SetImage takes a RGB format, i.e. a single pixel is composed of 24 bits or 1 byte Red, 1 byte Green and 1 byte Blue.

Most likely the error is because your pixel array source is not long enough.

STeven.
SetImage - ArrayOut of bound exception
Abhishek Verma from India  [6 posts]
10 years
No Steven,
In SetImage we are writing bytes like this
bufferedWriter.write(pixels, 0, width*height*3)
So i have pixel size 786432 which is exactly equal to 1024*768*3
Problem is somwhere else.ArrayIndexOutOfBoundsException will come when we try to acess array more then its bound means we are tring to acess pixels more then 786432 size and its happening inside bufferwriter.
I guess there will not be a problem from Roborealm fot sending 786432 length data at one shot.
SetImage - ArrayOut of bound exception
Anonymous
10 years
Hi Steven, Got the problem...width*height*3 is greater then array size.

Soon i will be known for such silly mistakes :-)
Any how Thanks for your effort
SetImage - ArrayOut of bound exception
Anonymous
10 years
Hi Steven,
               I have a doubt,as you told image length should be width()*height()*3 for RGB. What if i have gray scale image.do we need to have RGB values in that data.

Regards,
Abhishek
Anonymous 10 years
For gray scale images just tripple each single byte and you have a grayscale image in "RGB" mode. Its not terribly space efficient but it does allow for the same interface for grayscale and color images.

STeven.

This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 New Post   Forum Index