If we analyze images processing precisely we found that there are main three stage starting from source image then processing operation and at the end the resultant destination image object.
We can get a BufferedImage from a specific file using the following code:
BufferedImage img = ImageIO.read(new File("c:\\example.jpg"));
// here ImageIO is used to read the image from the file at location "c:\example.jpg"
or get an Image object using code :
Image image = new Image(display, "exampleFile.gif");
// where display is the object of class Display getting by Display display = new Display();
To display the image on screen we use Graphics of the container (defined in AWT)class, Let the container would be frame then,
Graphics2D g = (Graphics2D) frame.getRootPane().getGraphics();
//Get the surfaces Graphics object
g.drawImage(img, null, 0, 0); // Now draw the image at 0,0 on the frame.
After some operations on image we can save the image in the local disk using the code :
ImageIO.write (img, "png", new File(“C:\\resultImage”+ ".png"));
// The three write method's parameters are :
img – a RenderedImage to be written.
"png" – The FormatName, a String contains the informal name of the format.
Output – a File to be written to.