Why does we need ImageIcon instead of Image?

Hi,

Why do you need ImageIcon in this case?

Image origImg = ImageIO.read(imageData);

origImg = origImg.getScaledInstance(newImgWidth, newImgHeight,

Image.SCALE_AREA_AVERAGING);

origImg =new ImageIcon(origImg).getImage();

BufferedImage bimage =null;

bimage =new BufferedImage(origImg.getWidth(null), origImg.getHeight(null),

BufferedImage.TYPE_INT_RGB);

Why cant we deal directly with origImg instead of ImageIcon(origImg).getImage()?

[662 byte] By [amishera2006a] at [2007-11-27 7:37:50]
# 1

I see you make two redundant copy of your image, one you lose... why?

Maybe if you are more specific with your question?

Here is some stuff tahan can help you:

Image.- When you create an Image by reading data from an external source, like from internet or even your hard drive, is that the constructor will return quickly. I mean not all the data is adquired at creation time, you can get half image. Internally it creates a thread to adquire all the reaminding data and yo have to implements some interfaces called image observers and media trackers....

ImageICon.- The constructor wait for all the data to be retrieved.

RaulHuertasa at 2007-7-12 19:18:28 > top of Java-index,Security,Cryptography...
# 2

Hi,

Thanks for your explanation. Now this is clear.The ImageIcon is created as an alternative to mediatracker. Thaz why I have seen many people using that.

But there is still another question. Why is the name ImageIcon? It suggests that you are creating an icon not an oridnary image.

PS: The code is not mine. So being more specific is not possible for me. What I know is that the code is used for image scaling.

amishera2006a at 2007-7-12 19:18:28 > top of Java-index,Security,Cryptography...
# 3
I don't know about the name.. maybe because ImageIcon is from swing.... I really don't knowIf you find why post it here! :)Bye!
RaulHuertasa at 2007-7-12 19:18:28 > top of Java-index,Security,Cryptography...