Could anyone explain to me in noob way what the difference is betweeen ImageIcon and Image classes/objects in Java? Thanks
Asked
Active
Viewed 1.3k times
14
-
1Is this homework? Everything needed to answer this question should be documented in the javadocs. – user1329572 Jun 25 '12 at 19:27
-
15No it is not a homework. For this question like for the great majority of my other questions regarding Java, the info can be found in javadocs. But if I could understand everything from javadocs I wouldnt need any books, forums, or google or even internet for that matter. – ps-aux Jun 27 '12 at 17:33
2 Answers
12
Their nature and application is different. Image is an abstract superclass of all classes that represent graphical images. ImageIcon is an implementation of Icon
interface that uses Image
as its source.
Edit: Think of an Image
as something that could be rendered and an ImageIcon
as something that will be rendered as an Icon
when its paintIcon()
method is called.
Edit: The links above will take you to the JDK 6 api. These links will take you to the JDK 8 api: Image and ImageIcon.

Mark Said Camilleri
- 388
- 6
- 20

tenorsax
- 21,123
- 9
- 60
- 107
-
Ok so `ImageIcon` object has an underlying `Image` object and provides an extra layer with methods to manipulate this image? Also, `Icon` can be implemented in number of ways and not necessarily to have the underlying image (for example painting a label or rectangle). Or am I wrong? I just don't fully understand, if icon is just a small image, why to have two different classes for that. – ps-aux Aug 10 '13 at 13:49
-
3@LeNoob `Icon` is typically used to decorate components (labels, buttons, etc), i.e. they are painted on something. `Image`, on the other hand, is not only for displaying, it can be used to draw on it. Take a look at [Images](http://docs.oracle.com/javase/tutorial/2d/overview/images.html) tutorial for some examples. [How to Use Icons](http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html) can also be useful. – tenorsax Aug 14 '13 at 04:03
3
You can scale and save Image, but you can't do it with ImageIcon. For creating pictures in your GUI you usually have to use ImageIcon, but if you don't wanna do that, Image should be better.

Nicolas
- 950
- 1
- 7
- 15
-
But if `ImageIcon` has underlying image, how come I cannot save it and scale it? – ps-aux Aug 10 '13 at 13:50