error creating image
Im getting error when trying to create an image from array
when i am reading the image as array from the network
publicvoid write(OutputStream out)throws IOException{
DataOutputStream dout =new DataOutputStream(out);
//Write mood name
dout.writeUTF(m_moodName);
if(m_img ==null){
//Write there is no image
dout.writeBoolean(false);
}else{
//Write there is image
dout.writeBoolean(true);
PngEncoder pngEncoder =new PngEncoder(m_img);
byte[] array = pngEncoder.pngEncode();
//Write the array length
dout.writeInt(array.length);
//Write the array
dout.write(array);
dout.flush();
}
}
publicvoid read(InputStream in)throws IOException{
DataInputStream din =new DataInputStream(in);
//Read mood name
m_moodName = din.readUTF();
//Read if there is image
boolean bool = din.readBoolean();
if(bool ==true){
//Read byte array length
int length = din.readInt();
byte[] array =newbyte[length];
//Read to byte array
din.readFully(array);
m_img = Toolkit.getDefaultToolkit().createImage(array);
}
}
This is the exception that i am getting
Uncaught error fetching image:
java.lang.NegativeArraySizeException
at sun.awt.image.PNGImageDecoder.produceImage(Unknown Source)
at sun.awt.image.InputStreamImageSource.doFetch(Unknown Source)
at sun.awt.image.ImageFetcher.fetchloop(Unknown Source)
at sun.awt.image.ImageFetcher.run(Unknown Source)
I am getting this error from this line... (i think)
m_img = Toolkit.getDefaultToolkit().createImage(array);
and here is PNG encoder that i am using
http://catcode.com/pngencoder/
please help...
shay

