开发者

How to cast/convert a BufferedImage into an Image?

开发者 https://www.devze.com 2023-01-26 18:38 出处:网络
I would like to convert a BufferedImage to an java.awt.Image. My source-image is tif so I use JAI to read it as PlanarImage:

I would like to convert a BufferedImage to an java.awt.Image.

My source-image is tif so I use JAI to read it as PlanarImage:

PlanarImage source = JAI开发者_如何学Go.create("fileload", IMG_DIR + tagImgName);

I then save it as an objects attribute as a BufferedImage

tagImg = source.getAsBufferedImage();

For .pdf-Export (via iText) I need it as java.awt.Image

Thanks!


java.awt.image.BufferedImage is already a subclass of java.awt.Image, so you shouldn't need any casting or converting. You can use the BufferedImage in place of a Image.

You can do directly this:

Image tagImg = source.getAsBufferedImage();
// use tagImg with iText library here


Assuming you mean java.awt.image.BufferedImage, it already subclasses java.awt.image.Image - so you shouldn't need to do anything.

0

精彩评论

暂无评论...
验证码 换一张
取 消