ImageObserver Class in Java Simplified

ImageObserver Class in Java
ImageObserver Class in Java

ImageObserver Class in Java:


ImageObserver is an abstract interface used to get notification as an image is being generated.This interface defines method and associated constants used by classes that want to receive information about the status of the image. This communication happens asynchronously. drawImage() method takes both an Image object and an Image Observer object to draw an image perfectly.
In case of an ImageObserver object because ImageObserver is an interface, we need to pass a reference to an instance of a class that implements the ImageObserver interface.

Classes that are implementing ImageObserver interface are required to have an method called imageUpdate() redefined.Many methods that query information about an image take an ImageObserver as an argument.As soon as the information available the information is passed to. Component are the major ones that implement this interface.

How an Image is drawn:

When an Image object is referred, the imageUpdate() of that object will call repaint() which will intern call paint() method.The drawImage() method is called again.It draws all the pixel data. It has loaded so far which at this point should be more that what has been loaded last time when drawImage() method was called.
The partial image is again drawn and this time because more data has been loaded,imageUpdate() is again called.The cycle continues until all the pixel data has been loaded and completed image has been drawn.
A summary of imageUpdate() status is passed in through info,against which the static variable ALLBITS is tested.If we have not yet received all the bits in our image,we add the height  value to the total number of scanned lines processes. This will be printed in the system console.The run() method repaints five times a second(in every 200 miliseconds) while image is not loaded.How long the status monitor will run depends on how quickly the network connection can deliver the image data.

The interface structure of ImageObserver is given as:



public abstract interface ImageObserver{
//constants:
public static final int ABORT;
public static final int ALLBITS;
public static final int ERROR;
public static final int FRAMEBITS;
public static final int HEIGHT;
public static final int PROPERTIES;
public static final int SOMEBITS;
public static final int WIDTH;
public abstract boolean imageUpdate(Image img,int status,int x,int y,int width,int height);
//where Image img- is the object reference that will be drawn
//int status-status information of the Image img being processed.The status information as 
//an integer is tested bitwise against the value of one or more flags
//int width and int height- are the configuration rectangle.
}
 

Different bits are written below:


Bits Indicator
WIDTH The width of the base image is now available and can be taken from width argument
HEIGHT The height of the base image is now available and can be taken from height argument
PROPERTIES The properties of the base image is now available and can be taken from properties argument
SOMEBITS More pixels needed for drawing a scaled variation of the image are available.The bounding box
of the new pixels can be taken from x,y, width and height argument.
FRAMEBITS Another complete frame of a multiple frame image,which was previously drawn is now available
to be redrawn.The x,y,height,width arguments should be ignored
ALLBITS The image being drawn is complete and can be drawn again in its final form.
The x,y,width and height are no longer meaningful.
Error An image was being tracked has encountered an error.No further image information will be available and drawing will fail.
ABORT An image was being tracked was aborted before production was completed.No image information will be available.


ImageObserver Class in Java Simplified ImageObserver Class in Java Simplified Reviewed by Animesh Chatterjee on December 28, 2018 Rating: 5

No comments:

Powered by Blogger.