The principle is correct, but you may try to save it like ImageDialog
does:
See its buttonPressed() method:
try
{
ImageData imageData = new ImageData( new ByteArrayInputStream JavaDoc( this.newImageRawData ) );
if ( imageData.type != this.requiredImageType )
{
ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { imageData };
ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
imageLoader.save( baos, this.requiredImageType );
this.newImageRawDataInRequiredFormat = baos.toByteArray();
}
else
{
this.newImageRawDataInRequiredFormat = this.newImageRawData;
}
}
catch ( SWTException swte )
{
this.newImageRawDataInRequiredFormat = null;
}
Note: When it saves an image, it does use the following code:
try
{
File JavaDoc file = new File JavaDoc( returnedFileName );
FileOutputStream JavaDoc out = new FileOutputStream JavaDoc( file );
out.write( currentImageRawData );
out.flush();
out.close();
}