我正在使用此类swt.graphics.ImageLoader
将文件另存为PNG:
ImageLoader loader = new ImageLoader();
loader.data = new ImageData[] { m_imgdat };
loader.save(selected, SWT.IMAGE_PNG);
但有时我得到的文件不完整。最后一行像素是黑色的,有些程序(photoshop)拒绝完全打开它。
我有什么遗漏的吗?我怎样才能告诉这个类刷新文件并关闭它?
最佳答案
原理是正确的,但是你可以尝试像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;
}
<小时/>
注意:当它saves an image时,它确实使用了以下代码:
try
{
File JavaDoc file = new File JavaDoc( returnedFileName );
FileOutputStream JavaDoc out = new FileOutputStream JavaDoc( file );
out.write( currentImageRawData );
out.flush();
out.close();
}
关于java - swt.graphics.ImageLoader.save() 未刷新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/673159/