I’ve read the java api, but I still do not understand the main difference between:
1) ImageIcon
2) BufferedImage
3) VolatileImage
4) Image
Can someone tell me when each one is used?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I wouldn’t call this explanation below the absolute standard of using Java Image types, but these are the rules of thumb that I follow:
1. ImageIcon
This is typically used when you have small images that you want to add to buttons or to use as window icons. These may be created directly from anything that implements the
Imageinterface.2. BufferedImage
Typically used when you need to manipulate individual pixels within an image, or when you want to double-buffer a custom
paint(Graphics g)method. The image resides in RAM, so it can take up a lot of space, and modifications toBufferedImageinstances are not typically hardware-accelerated.3. VolatileImage
Hardware-accelerated image, so it’s fast, but you run the risk of the hardware-backed buffer being overwritten before you’re done painting (although this rarely happens and according to Oracle, is only an issue for Windows-based machines). It’s a little more difficult to use than
BufferedImagefor double-buffering custompaint(Graphics g)methods, but is well worth it if you find yourself doing a lot of pre-processing before rendering to screen.4. Image
This is basically just an interface that defines some bare-bones functionality that every
Imageshould have. You should use this when you don’t need to modify an image’s contents and/or want to make methods that handle read-only-image data most flexible.