Image Fundamentals: Creating, Loading and Displaying Java Help

Image ‘Fundamentals: Creating, Loading and Displaying

There are three common operations that occur when you work with images: creating an-image, loading an ~age, and displaying an image. In Java, the Image class is used to refer to images in memory and to images that must be loaded from external sources. Thus, Java provides ways for you to create a new image object and way’s to load. one. It also provides a means by which an image can be displayed. Let’s look at each: You might expect that you create a memory image using something like the following I Image  new Image(200, 100?; II error  won’t work Not so. Because images must eventually be painted on a window to be seen, the Image class doesn’t have enough information about its environment to create the proper data format for the screen. Therefore, the Component class in java.awl has a factory method called create Image that Is used to create objects. (Remember that all of the  AWT components are subclasses of Component, so all support this method.)

The createimage method has the following two.forms:

Image createImage(imageProducer imgProd)
Image createimage(int width, int ‘height)

The first form returns an image produced by imigPro, which is an object of’a class that implements the ImageProducer interface. (We will look at image producers later.) The second form returns a blank (that is, empty) image that has the specified width and height. Here is an example: This creates an instance of Canvas and then calls the createImage( ) method to actually make an Image object. At,thi~ point, the image is blank. Later you will see how to write data to it.

JavaHelpOnline.com

  • Feel free to send us an inquiry, we will reply back in hours.
 

Verification

Posted on September 18, 2014 in The Complete Reference Images

Share the Story

About the Author

Back to Top