Hi,
I have an application sending JPEGs via a TCP connection.
By now I used a Delphi program on the other side to receive the pics.
Now I want to create a Java applet that does the work of the Delphi
program, but I have problems reading the pics from the socket's
stream.
Here's my code:
8<--------------------------------------------------
public BufferedImage getImage()
{
BufferedImage image;
try
{
ImageInputStrea m stream = ImageIO.createI mageInputStream (
_cSocket.getInp utStream() ); // _cSocket is of class Socket
image = ImageIO.read( stream );
}
catch( Exception e )
{
System.err.prin tln( e );
}
return image;
}
-------------------------------------------------->8
The function returns null. There seems to be no appropriate
ImageReader.
Now, when I add the following lines to the function, it works fine:
8<--------------------------------------------------
while( _cSocket.getInp utStream().avai lable() > 0 )
{
byte[] b = new byte[2];
int c = _cSocket.getInp utStream().read ( b );
if( b[0] == 0xFF && b[1] == 0xD9 ) // FF D) are the last two byte
of a JPEG
break;
}
-------------------------------------------------->8
But that's not exactly what I wanted. I guess it skips every second
pic.
Can anybody explain this phenomenon.
My setup:
Windows 2000
Java 1.4.2_02
I have an application sending JPEGs via a TCP connection.
By now I used a Delphi program on the other side to receive the pics.
Now I want to create a Java applet that does the work of the Delphi
program, but I have problems reading the pics from the socket's
stream.
Here's my code:
8<--------------------------------------------------
public BufferedImage getImage()
{
BufferedImage image;
try
{
ImageInputStrea m stream = ImageIO.createI mageInputStream (
_cSocket.getInp utStream() ); // _cSocket is of class Socket
image = ImageIO.read( stream );
}
catch( Exception e )
{
System.err.prin tln( e );
}
return image;
}
-------------------------------------------------->8
The function returns null. There seems to be no appropriate
ImageReader.
Now, when I add the following lines to the function, it works fine:
8<--------------------------------------------------
while( _cSocket.getInp utStream().avai lable() > 0 )
{
byte[] b = new byte[2];
int c = _cSocket.getInp utStream().read ( b );
if( b[0] == 0xFF && b[1] == 0xD9 ) // FF D) are the last two byte
of a JPEG
break;
}
-------------------------------------------------->8
But that's not exactly what I wanted. I guess it skips every second
pic.
Can anybody explain this phenomenon.
My setup:
Windows 2000
Java 1.4.2_02
Comment