Hi,
I first convert the image on the server application in bytes:
//server
public void sendImage(File file) throws IOException {
ByteArrayOutputStream baos=new ByteArrayOutputStream(1000);
BufferedImage img=ImageIO.read(new File(file.getAbsolutePath()));
ImageIO.write(img, "jpg", baos);
baos.flush();
os.write(baos.toByteArray());// this is a "new DataOutputStream(clientSocket.getOutputStream());"
System.out.println("Done! Length is:"+baos.toByteArray().length);
baos.close();
}
Then my application freezes when trying to convert the bytes array back to image.
//client
public void receiveImage() throws IOException
{
byte[] bytearray = new byte[4096];
is.readFully(bytearray);// "new DataInputStream(clientSocket.getInputStream());" here my app freezes. and i don't knwo array length.
BufferedImage imag=ImageIO.read(new ByteArrayInputStream(bytearray));
ImageIO.write(imag, "jpg", new File("abc.jpg"));
this.setLayout(new FlowLayout());
this.add(new ImagePanel(imag));
this.validate();
}
I probabily done something wrong... Is this a good aproach to transfer images fast?
Can someone help please?