WritableImage转BufferedImage
时间: 2023-10-24 22:09:38 浏览: 65
jxl对excel添加水印(含有setWaterMarkImage方法).zip
可以使用以下代码将 WritableImage 转换为 BufferedImage:
```java
WritableImage writableImage = ...; // 获取 WritableImage 对象
BufferedImage bufferedImage = new BufferedImage(writableImage.getWidth(), writableImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
WritableRaster writableRaster = bufferedImage.getRaster();
WritableRaster writableRaster2 = writableImage.getRaster();
int[] buffer = new int[writableImage.getWidth() * writableImage.getHeight()];
writableRaster2.getDataElements(0, 0, writableImage.getWidth(), writableImage.getHeight(), buffer);
writableRaster.setDataElements(0, 0, writableImage.getWidth(), writableImage.getHeight(), buffer);
```
这个代码将 WritableImage 转换成了 BufferedImage,并且将像素数据从 WritableRaster 转移到了 BufferedImage 的 WritableRaster 中。你可以使用 `bufferedImage` 变量来操作 BufferedImage 对象。
阅读全文