want to display image from BufferedImage

hi

i just wanted to know that

how do display and image from BufferedImage object

this is my prog in which i am capturing the image of the screen

i just wanted to show it on screen

how to do that

plzzzzzzzzz

here i sprogram

import java.awt.AWTException;

import java.awt.Robot;

import java.awt.Rectangle;

import java.awt.Toolkit;

import java.awt.image.BufferedImage;

import java.io.*;

import javax.imageio.ImageIO;

class ScreenCapture {

public static void main(String args[]) throws

AWTException, IOException {

// capture the whole screen

BufferedImage screencapture = new Robot().createScreenCapture(

new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()) );

// Save as JPEG

// Save as PNG

// File file = new File("screencapture.png");

// ImageIO.write(screencapture, "png", file);

}

}

[955 byte] By [bhavin123400a] at [2007-11-27 5:52:49]
# 1

Use [url http://forum.java.sun.com/help.jspa?sec=formatting]code formatting[/url] when posting code.

Here's a simple example for displaying a BufferedImage:

import java.awt.Color;

import java.awt.Graphics;

import java.awt.image.BufferedImage;

import javax.swing.ImageIcon;

import javax.swing.JFrame;

import javax.swing.JLabel;

public class BufferedImageTest {

public static void main(String[] args) {

try {

JFrame frame = new JFrame();

BufferedImage image = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB);

Graphics g = image.createGraphics();

g.setColor(Color.WHITE);

g.fillRect(0, 0, image.getWidth(), image.getHeight());

g.setColor(Color.BLUE);

g.drawRect(50, 50, 200, 200);

g.dispose();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(new JLabel(new ImageIcon(image)));

frame.pack();

frame.setVisible(true);

} catch (Exception e) {e.printStackTrace();}

}

}

Rodney_McKaya at 2007-7-12 15:44:41 > top of Java-index,Security,Cryptography...