原理是正确的,但是您可以尝试像这样保存它ImageDialog
:
查看它的buttonPressed()方法:
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;
}
注意:当它保存图像时,它确实使用以下代码:
try
{
File JavaDoc file = new File JavaDoc( returnedFileName );
FileOutputStream JavaDoc out = new FileOutputStream JavaDoc( file );
out.write( currentImageRawData );
out.flush();
out.close();
}