View RSS Feed

Java AWT

Creating and Drawing to an Image

Rate this Entry
by , 03-07-2012 at 05:03 PM (518 Views)
The process of loading an image is already known, which is created as well as stored on any network or your system. However, you would also want to make a new pixel data buffered image.

BufferedImage object can be created manually by making use of 3 constructors of class:
  • new BufferedImage(width, height, type) - creates a BufferedImage for one of the predefined type of image.
  • new BufferedImage(width, type,height, colorModel) - creates a BufferedImage of the predefined images: TYPE_BYTE_BINARY orTYPE_BYTE_INDEXED.
  • new BufferedImage(colorModel, raster, premultiplied, properties) - creates a new BufferedImage along with a ColorModeland Raster.


Component class methods could also be used, on the other hand. For a GraphicsConfiguration & given component, such methods might do the analysis of the display resolution to construct an appropriate type image.
  • Component.createImage(width, height)
  • GraphicsConfiguration.createCompatibleImage(width, height)
  • GraphicsConfiguration.createCompatibleImage(width, height, transparency)


BufferedImage type’s object is returned by the GraphicConfiguration. However, object of Image type is returned by the Component, if instead BufferedImage is needed than one may perform instanceof and also may cast BufferedImage in code.

Images are not only rendered on screen. Image can be taken as a drawing surface. CreateGraphics() method of BufferedImage class can be used for such purposes:
Java Code:
BufferedImage off_Image =
  new BufferedImage(100, 50,
                    BufferedImage.TYPE_INT_ARGB);

Graphics2D g2 = off_Image.createGraphics();

Submit "Creating and Drawing to an Image" to Facebook Submit "Creating and Drawing to an Image" to Digg Submit "Creating and Drawing to an Image" to del.icio.us Submit "Creating and Drawing to an Image" to StumbleUpon Submit "Creating and Drawing to an Image" to Google

Comments