Methods to create, load, display images in Java: createImage, getImage, drawImage

createImage( ) method: createImage( ) method is used to create an image object. It is defined in Component class in java.awt package.


By implementing ImageProducer interface:

Image createImage(ImageProducer imgprod)

To create an empty image with width and height:

Image createImage(int width, int height)

getImage( ) method: getImage( ) method is used to load an image. It is defined in Applet class.


By using image URL:

Image getImage(URL url)

By using image URL and image name:

Image getImage(URL url, String imgname)

drawImage( ) method: drawImage( ) method is used to display images. It is defined by Graphics class.


boolean drawImage(Image imgob, int left, int top, ImageObserver imgob)

where, imgob is image object, upperleft corner of image is specified by left and top.

Leave a Reply