简体   繁体   中英

How to cast/convert a BufferedImage into an Image?

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.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

假设你的意思java.awt.image.BufferedImage ,它已经子类java.awt.image.Image -所以你不需要做任何事情。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM