Sunday, January 8, 2012

Drawing an Image on the Screen using Graphics2D

public class ImageApp {
public void loadAndDisplayImage(JFrame frame) {
// Load the img
BufferedImage loadImg = ImageUtil.loadImage("C:/Images/duke.gif");
frame.setBounds(0, 0, loadImg.getWidth(), loadImg.getHeight());
// Set the panel visible and add it to the frame
frame.setVisible(true);
// Get the surfaces Graphics object
Graphics2D g = (Graphics2D)frame.getRootPane().getGraphics();
// Now draw the image
g.drawImage(loadImg, null, 0, 0);
}
public static void main(String[] args) {
ImageApp ia = new ImageApp();
JFrame frame = new JFrame("Tutorials");
ia.loadAndDisplayImage(frame);
}
}
Running Codes

0 comments:

Post a Comment

Tu comentario será moderado la primera vez que lo hagas al igual que si incluyes enlaces. A partir de ahi no ser necesario si usas los mismos datos y mantienes la cordura. No se publicarán insultos, difamaciones o faltas de respeto hacia los lectores y comentaristas de este blog.