Hi,
- For opening image i have to use java.awt.Image class.
- For saving drawn image to jpg i have to use ImageIo class.
- So for passing ImageIO.write() method i need image object to bufferedImage object.
/*
* Program for Converting Image Object to BufferedImage Object
* Copyright 2009 @ yuvadeveloper
* Code By:- Prashant Chandrakar
*
*/
import java.awt.*;
import java.awt.image.*;
class Convert
{
public static void main(String as[])
{
////opening image in Image Object
Image img = Toolkit.getDefaultToolkit().getImage("test.jpeg");
////taking dimension of image
int width = img.getWidth(null);
int height = img.getHeight(null);
////creating a bufferedImage object of same dimension as image
BufferedImage bimg = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
////taking graphics object from BufferedImage
Graphics2D gg = bimg.createGraphics();
////drawing Image objects image into graphics of buffered image object
gg.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
///disposing graphics.
gg.dispose();
}
}
thanks a lot
ReplyDeleteThanks a lot, its helps me great
ReplyDelete