Display Image using Java2D

Display Image using Java2D

Posted in : Core Java Posted on : October 29, 2010 at 5:15 PM Comments : [ 0 ]

This section contains the detail about the Display Image using Java2D in java Swing.

Display Image using Java2D

One of the most important capabilities of Java2D API is to display image. An image is an array of pixels. Each pixel represents a color at a given position. We can use components like JLabel to display an image, or we can draw it using the Java 2D API.

Example :

Given below example will display image on panel :

package corejava;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Java2DImage extends JPanel {
	public void paintComponent(Graphics g) {

		Graphics2D g2d = (Graphics2D) g;
		Image image = new ImageIcon(

		g2d.drawImage(image, 0, 0, null);

	public static void main(String[] args) {

		Java2DImage image = new Java2DImage();
		JFrame frame = new JFrame("Java2D Image");
		frame.setSize(380, 320);


Output :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics