Home Answers Viewqa Java-Beginners displaying image in awt

 
 


mln15584
displaying image in awt
2 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners

View Answers

July 16, 2008 at 6:39 PM


Hi friend,

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

class imageLoad extends Canvas {
Image img;
public imageLoad(Image img) {
this.img = img;
}
public void paint (Graphics g) {
if (img != null)
{
g.drawImage(img, 0, 0, 1000, 1000, this);
}
}
public void setImage (Image img){
this.img = img;
}
}
public class ImagesLoading implements ActionListener{
JFrame fr = new JFrame ("Image loading program Using awt");
Label Label1 = new Label("Label1 ");
Button Button1 = new Button("Click Here");
Image Image1;
imageLoad Canvas1;
FileDialog fd = new FileDialog(fr,"Open", FileDialog.LOAD);

void initialize (){
fr.setSize(500,500);
fr.setLocation(300,300);
fr.setBackground(Color.lightGray);
fr.setLayout(new FlowLayout());
fr.add(Label1);
fr.add(Button1);
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Button1.addActionListener(this);
Canvas1 = new imageLoad(null);
Canvas1.setSize(1000,1000);
fr.add(Canvas1);
fr.show();
}
void imageload () {
fd.show();
if(fd.getFile() == null){
Label1.setText("You have not chosen any image files yet");
}
else{
String d = (fd.getDirectory() + fd.getFile());
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image1 = toolkit.getImage(d);
Canvas1.setImage(Image1);
Canvas1.repaint();
}
}

public void windowClosing(WindowEvent e){
System.exit(0);
}
public void windowActivated(WindowEvent e){
}
public void windowClosed(WindowEvent e){
}
public void windowDeactivated(WindowEvent e){
}
public void windowDeiconified(WindowEvent e){
}
public void windowIconified(WindowEvent e){
}
public void windowOpened(WindowEvent e){
}
public void actionPerformed(ActionEvent event){
Button b = (Button)event.getSource();
if(b == Button1){
imageload();
}
}
public static void main(String args[]){
ImagesLoading a = new ImagesLoading();
a.initialize();
}
}

---------------------------------------------------

Read for more information,

http://www.roseindia.net/java

Thanks

July 17, 2008 at 10:58 AM


You can use JAI (Java Advanced Imaging) to display an image.

eg.,

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.media.jai.JAI;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ImagePanel extends JPanel
{
private BufferedImage image;

public ImagePanel(String fileName)
{
image = JAI.create("fileload",fileName).getAsBufferedImage();
setPreferredSize(new Dimension(image.getWidth(),image.getHeight()));
}

public void paint(Graphics g)
{
if(image != null)
g.drawImage(image, 0, 0, this);
}

public static void main(String[] args)
{
ImagePanel panel = new ImagePanel("D:/Sunset.jpeg");
JFrame frame = new JFrame("Image Frame");
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(panel.getPreferredSize());
frame.setResizable(false);
frame.setVisible(true);
}
}

-Thanks
Ramesh A.V









Related Pages:
displaying image in awt - Java Beginners
displaying image in awt  Hi All, I have downloaded the code to display image using awt from here and when I execute the code I am getting... ActionListener{ JFrame fr = new JFrame ("Image loading program Using awt"); Label
Image is not displaying
Image is not displaying  Hii i am using spring javamail with html template to send mail,i am facing that image displaying prob when mail have to cm in gmail,in template just i am giving my current location of image which
displaying image
displaying image  how to upload image and retrieve it form database mysql in php?   Here is an example of uploading image using php. 1)form.html: <form method="post" enctype="multipart/form-data" action="upload.php
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
How to retrive an inmage from database and displaying it in imgae box - Swing AWT
How to retrive an inmage from database and displaying it in imgae box ...? I want to retrive an image from database and to display it in a small imagebox... = con.createStatement(); ResultSet rs =stmt.executeQuery("select image from image where image
AWT Image
AWT Image  I have loaded two images using toolkit in java.one is concentric rectangle and other is concentric circle.kindly someone send me the source code of interchanging the inner most rectangle with the inner most circle
Displaying image using jsp and spring.
Displaying image using jsp and spring.  how to display an image stored in WEB-INF/images folder on the browser using jsp and spring
loading image - Swing AWT
loading image  give me a source code to add any wallpaer of my PC as a background image to jpanel on a jframe
Image Selection - Swing AWT
Image Selection  Hi, I need to provide the image selection facility... click on any item, the image of that item should be selected as done in windows...; JButton saveButton; public DisplayImage() { super("Image Selection program
Displaying image with byte array[] - Java Beginners
Displaying image with byte array[]  Hi Frndz.. As per my requirement i need to show an image by using an byte array object which have image data... this only i have to image , i don't have any Inputstream object. If u have
problen in displaying the text and image in gallery using Android
problen in displaying the text and image in gallery using Android   public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gallery = (Gallery
AWT programmes - Swing AWT
AWT programmes  I need few programs for menus in AWT. how to open a filed dialog window, and how to save a image in the save window when we press... has all AWT programms which must open,save and make changes to a particular
image displaying from database with some other information
image displaying from database with some other information  hi, in the following section of code when i am not displaying the image it is working properly but when i tried to display the image nothing is displayed on browser
Java AWT Package Example
to be displayed on the frame.   Image Size This Java awt (Abstract... Java AWT Package Example       In this section you will learn about the AWT package of the Java
Displaying image when clicked on URL in jsp - JSP-Servlet
Displaying image when clicked on URL in jsp  Hi, I am using... in displaying the image from the folder. Regards, Anish... For Screenshot : abc.jpg here abc.jpg is a url and when clicked would show me an image
Image Size
Image Size       This Java awt (Abstract Windowing Toolkit) tutorial describes about the image size...; This program helps you in setting an image and getting the size of its
awt swings - Swing AWT
awt swings  hello sir, My requirement is to insert captured image......  Hi friend, This code will be captured your image. Please...(); BufferedImage image = robot.createScreenCapture(new Rectangle
forwarding request to a jsp from a filter and displaying image in that jsp
forwarding request to a jsp from a filter and displaying image in that jsp ... correctly, but in login.jsp the image is not displaying. Can you help me in resolving this problem. Thanks & Regards, Suresh   Jsp Display Image <
Java logical error - Swing AWT
Java logical error  Subject:Buttons not displaying over image Dear... on it. But the buttons are not displaying properly. So,I request your kind help. I have... image; private JPanel panel = new JPanel(new GridLayout(4,2
how to set a image in frame? - Swing AWT
how to set a image in frame?  how to set a image in frame using swing
displaying both image and records problem in jsp and servlet - JSP-Servlet
displaying both image and records problem in jsp and servlet  hello, Thanks for your reply on the question i asked the other time. It worked perfectly, but it's still not what i want. What i want is that, i want
Error in laodin and saving the image . - Swing AWT
Error in laodin and saving the image .  I am a student who had... facing problem while laoding and saving the image with help of JFileChooser class... class UploadImage extends JPanel { static BufferedImage image; static File
Displaying the same image in a JPanel and using scroll - HELP - Java Beginners
Displaying the same image in a JPanel and using scroll - HELP  I hope someone can help me out here. I want to display an image in a JPanel which contain a Scroll, so using the scroll I want to see the first image displayed
how to retrive other details with an image - Swing AWT
to retrive an image as well as some other values from database.. but only image..... followingis my code..plz advice me how to get both values as well as image at a same...("Select visitor_firstname,Type_code, image_data from visiting_details where Ticket
java image loadin and saving problem - Swing AWT
java image loadin and saving problem  hey in this code i am trying to load a picture and save it.........but image is only visible whn we maximize... extends JPanel { static BufferedImage image; static File file=null; Image img
Image on Frame in Java AWT
Image on Frame in Java AWT       Introduction In this section, you will learn how to display image on the frame. This program shows you how to display image in your application
put image on form creating in swing-swing code - Swing AWT
put image on form creating in swing-swing code  i want to display image on swing panel and get the image co ordinate by mouse clicking.and also zoom the image at particular area of image. please give solution on my email id
displaying data from ms excel in form.
displaying data from ms excel in form.  Hi all, I have a requirement... (image.jpg). I am storing the image file in another folder. Could anyone get me some logic on how to link this image from my folder to the image.jpg mentioned
displaying employee records and their images problem - JSP-Servlet
displaying employee records and their images problem  hi, Thanks for your reply to my question. The code you sent to me yesterday was not working. it doesn't display any record and image. Please, help me out urgent
Image is in same folder where the java file is located - Swing AWT
Image is in same folder where the java file is located  dear sir It is there in the same folder..means the photograph.jpg file is created in the same folder where my java file is present... wat I should do sir
image display
image display  hello sir this is saurav srivastav, I am developing my website I have seen all the results of displaying and I got some good code for uploading image in ms access database and also seen the result of displaying
AWT
AWT  How to set size of button in awt
how to set image in button using swing? - Swing AWT
how to set image in button using swing?  how to set the image in button using swing?  Hi friend, import java.awt.*; import... FlowLayout()); getContentPane().add(myJButton); setTitle("Image on Button
awt
Java AWT Applet example  how to display data using JDBC in awt/applet
awt
JDBC and AWT to display data  how to display data using JDBC in awt/applet
awt
JDBC in awt applet  how to display data using JDBC in awt/applet
hybrid digital image embedding process using invisible watermarking - Swing AWT
hybrid digital image embedding process using invisible watermarking   sir/madam, I am subramanian from chennai.i did not create this project using rsa algorithm and i did not understand.please help me with source
displaying images and records problem - JSP-Servlet
displaying images and records problem  hi, Thanks for your reply to my question. The code you sent to me last week is not working. it doesn't display any record and image. I posted my question and since then no replay
awt
JDBC in awt  how to display data using JDBC in awt/applet
Java Program - Swing AWT
Java Program  A Java Program that display image on ImageIcon after selecting an image from the JFileChooser
swings - Swing AWT
swings  i want to retrieve image using histogram of that image and display the histogram in the screen that is my problem
swing - Swing AWT
swing  hi..please help me to retrieve image using histogram of that image   Hi Friend, Please clarify your problem.Do you want to create... in the form of image? Thanks
java - Swing AWT
& then clicked on this button,file dialog open & thn displayed selected image on panel.Then crop that image & save it.. plzzzzzzz.......reply as soon... java.awt.image.FilteredImageSource; public class Upload extends JPanel { BufferedImage image
java - Swing AWT
java  hello..sir.....plzzzzzzz help me to display selected image... { BufferedImage image; public DisplayImage() { try { System.out.println("Enter image name\n"); BufferedReader bf=new BufferedReader(new
swing - Swing AWT
in the tabbedpane.One is displaying textfield and another is displaying
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
adding buttons - Swing AWT
adding buttons  can u plzz explain how to add button to a dialog box and make them perform some event on the image loaded on the panel
SWING - Swing AWT
SWING  how can i insert image in Jpanel by extending class with JFrame in swing?  Hi Friend, Try the following code: import java.awt...."); String image=f.getPath(); ImageIcon icon=new ImageIcon(image); l=new
java - Swing AWT
java  hi can u say how to create a database for images in oracle and store and retrive images using histogram of that image plz help me its too urgent
java swing - Swing AWT
java swing  how to add image in JPanel in Swing?  Hi Friend... DisplayImage extends JPanel{ private BufferedImage image; public DisplayImage() { try { image = ImageIO.read

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.