Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

VolatileBufferedToolkitImage Strategies

JavaFAQ Home » Swing, AWT Go to all tips in Swing, AWT

Bookmark and Share

A common question seems to arise often from Java graphics developers about which image type or creation method to use. When exactly should you use VolatileImage? What is BufferedImage appropriate for? What about the old Toolkit images? And when is BufferStrategy more appropriate than one of these image types?

It's a pretty big topic, and the answer (like all truly great answers) is probably "It depends". But there are some general guidelines that can come in handy.

Image Types

First of all, perhaps a short dictionary of image types might help:

  • Toolkit Image: This is the oldest kind of image object in the Java API. These images are created and returned by the old 1.x APIs such as Applet.getImage() and Toolkit.createImage(). These images are created from a pointer to a data source, such as a GIF or JPG file, and return an object of type Image. They are useful for convenient loading and storage of image data for display, but getting at the actual pixel data or manipulating it is not as easy.
  • BufferedImage: This is an image type that was created in the JDK 1.2 API. They were created for easier and more powerful manipulation of the actual pixel data in an image. At first, there was no way to load an image from a data source directly into a BufferedImage; these images were used, instead, to create an arbitrary buffer for pixel data, which you could then write to, read from, or display conveniently. The main way to get actual pixel data into a BufferedImage object at first was through use of rendering operations (after getting a Graphics object for the BufferedImage), or by manually setting the pixel data through methods in BufferedImage, WritableRaster, and DataBuffer. With the advent of the ImageIO API (see below) in JDK 1.4, it became possible to create a BufferedImage object directly from a data source, just like Toolkit images (only these BufferedImage objects are writable, unlike their Toolkit image cousins).
  • VolatileImage: This image type was created in JDK 1.4 as a means of creating and managing accelerated image memory. One of the problems with hardware acceleration for images is that, on some platforms, accelerated memory can be deleted out from under you at any time. This is obviously not what you want for your typical image data. To work around that, the VolatileImage API was created to provide a notification mechanism so that you know when an image must be re-rendered due to data loss. VolatileImage objects are not loaded from image data, but are just created as empty pixel buffers (much as the initial BufferedImage objects were (see above)); to load image data into a VolatileImage, applications must load the image data through some non-Volatile means, get the Graphics object for the VolatileImage, and then copy the data into the Graphics object using drawImage().
  • Managed Images: These image objects are not specific objects or APIs in Java, but are rather a concept of how we accelerate image operations. A "managed image" is one that you create through any of the normal image creation/loading methods and which we try to accelerate for you internally, by creating an accelerated mirror copy of the image data. This type of image can benefit from hardware acceleration without falling prey to the "surface loss" issues mentioned above for VolatileImage. I'll talk more about managed images and hardware acceleration later in the article.

That's it for the basic image types. Now let's talk about how we actually create and use these image objects.

Read the rest here

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy