Image or BufferedImage

Trying to write an application that displays a lot of images. Images would essentially be drawn onto JPanels. Was wondering what are the implications of using BufferedImage over Image. As far as I know BufferedImage are handy if you wanna gain access to the pixels. Is there any other good reason to consider using BufferedImage instead of Image? Would there be cost or benefit in performance when I have a class that holds and displays BufferedImage instead of just using Image?

Also, found that for relatively large images, using the following code to convert an Image to BufferedImage can take up to several minutes. Does anybody know a way to speed things up?

BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);

tracker.addImage(bi, 0);

Graphics g = bi.createGraphics();

g.drawImage(image, 0, 0, null);

g.dispose();

tracker.waitForID(0);

Many thanks on any advice you can give.

Jeev

[1011 byte] By [jeevandrasa] at [2007-11-27 11:37:42]
# 1

What is your process scenario and what is your requirement in handling those images? If you read the API documentation, you would see BufferedImage can do many things that the Image, an old API, can't.

hiwaa at 2007-7-29 17:15:59 > top of Java-index,Java Essentials,Java Programming...
# 2

> What is your process scenario and what is your

> requirement in handling those images? If you read the

> API documentation, you would see BufferedImage can do

> many things that the Image, an old API, can't.

Thanks Hiwa. Well as it is now, my application primarily just displays image. So I guess that pretty much answers my question that the old Image class would be sufficient. However, like you said BufferedImage can do more stuff than Image. So I thought perhaps it would be better to convert them to BufferedImage just in case in the future I would want my classes to do more than just display images. However, I am just trying to weigh the cost benefit of doing this. My application would hold several big images during runtime. I was just wondering if BufferedImage would come with a significant overhead (particularly memory) when compared to the plain old Image. As it is I have found that with the code I attached earlier, converting huge images from type Image to BufferedImage seem to involve a huge amount of processing. I am currently relying on a java twain scanner driver appended to Toolkit.createImage() to load images onto my application. This method returns type Image. I was just wondering if keeping the image as type Image would keep my overhead low and only convert them to BufferedImage when I need them for processing. Or perhaps, withstanding the sluggish conversion, there would not be any significant overhead in keeping them images as BufferedImage. Sorry, I hope i do make sense here. I am just concerned about my application becoming sluggish when it is working with many images at one time, so just trying to be thrifty with memory.

Many thanks again for your advice.

jeevandrasa at 2007-7-29 17:15:59 > top of Java-index,Java Essentials,Java Programming...
# 3

Use ImageIO.read() and you'll get a BufferedImage back directly. That old mediatracker stuff is worthless these days.

-Kayaman-a at 2007-7-29 17:15:59 > top of Java-index,Java Essentials,Java Programming...