• Post Reply Bookmark Topic Watch Topic
  • New Topic

error by encode->decode JPEG

 
Alexander Rubinov
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a function that encode and immediatelly decode the same JPEG-data.
There are (not all) a image that will be black after redecode.
Function is running in multithread environment.
source code:
------------------------------------------------
static public byte[] decode_encode_jpeg( byte[] source ) throws IOException
{
ByteArrayOutputStream os = null;
try
{
Image image = new ImageIcon( source ).getImage() ;
int width = image.getWidth(null);
int height = image.getHeight(null);
Dimension d = new Dimension(width,height);
BufferedImage bufferedImg = new BufferedImage( width, height, BufferedImage.TYPE_INT_RGB );
Graphics2D g2 = bufferedImg.createGraphics();
g2.drawImage(image, null, null);
os = new ByteArrayOutputStream();
JPEGImageEncoder jpegImgEncoder = JPEGCodec.createJPEGEncoder( os );
jpegImgEncoder.encode(bufferedImg);
return os.toByteArray();
}
finally
{
try{ if( os != null ) os.close(); } catch( Exception e ){};
}
}
------------------------------------------------
Is JPEGImageEncoder threadesave ? when yes, what is the problem?
Thanks,
Alexander.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!