package gui.practice;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JFrame;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedImageDemo1 window = new BufferedImageDemo1();
}
}
class BufferedImageDemo1 extends JFrame {
Image image;
BufferedImage bufImage;
public BufferedImageDemo1() {
super();
URL url;
try {
url = new URL("file:///D:/bird.jpg");
image = Toolkit.getDefaultToolkit().getImage(url);
int width, height;
width = image.getWidth(this);
height = image.getHeight(this);
bufImage = new BufferedImage(
width < 1 ? 500 : image.getWidth(this), height < 1 ? 500
: image.getHeight(this),
BufferedImage.TYPE_INT_ARGB);
Graphics2D g = bufImage.createGraphics();
g.drawImage(image, 0, 0, this);
this.setSize(300, 300);
setVisible(true);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}