我有一个 SWT 应用程序,用户可以将图像拖放到 Canvas 上。 放置后,我会在 SWT.graphics.Image 实例中跟踪图像。
现在我想使用 im4java 编辑图像并在 Canvas 对象上显示图像。 但我一直坚持将图像放入 IMOperation 对象中。
Image i = this.image; //image is stored in here
ConvertCmd cmd = new ConvertCmd();
IMOperation op = new IMOperation();
//how can i edit the image data using the op object?
是否可以通过这种方式编辑图像对象?
编辑:我试图在这里更具体: 我知道如何使用以下方法将图像加载到操作中:
IMOperation op = new IMOperation();
op.addImage("myimage.jpg");
但就我而言,我不想通过文件名加载图像,但我想使用 Image 实例。
op.setImageData(i.getImageData()) //does sth like this exist?
最佳答案
可能不是。您可以:
- 使用
BufferedImage
并在嵌入式 AWT 控件中显示它们。 - 使用
BufferedImage
和 convert them to/from SWT 。这很慢(根据我的经验),并且可能不适用于所有图像。 - 使用
ImageLoader
与 input/output streams 一起工作.
关于java - 在 im4java 中打开 SWT 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14687794/