Images in java

Images in java

how to handle images in java

View Answers

September 18, 2012 at 4:27 PM

Here is a simple example of displaying an image on frame.

import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

public class DisplayImage extends JPanel {
BufferedImage image;
DisplayImage(){
String f="c:/fruit.png";
File file = new File(f);
try{
image = ImageIO.read(file);
}
catch(Exception ex){}
repaint();
}
public void paint(Graphics g) {
g.drawImage( image, 0, 0, null);

}
public static void main(String[] args) {
JFrame frame = new JFrame();
JPanel p=new DisplayImage();
frame.add(p);
frame.setSize(300, 300);
frame.setVisible(true);
}
}

September 18, 2012 at 4:30 PM

Here is an example that allow the user to select any image file and display that image on frame.

import java.awt.*;
import java.io.*;
import javax.swing.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

public class DisplayImage extends JPanel {
BufferedImage image;
Image img;

JButton browse;
File file = null;
public DisplayImage() {

browse = new JButton("Display");
this.add(browse);
browse.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
chooser.addChoosableFileFilter(new ImageFileFilter());
int returnVal = chooser.showOpenDialog(null);

if(returnVal == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
try{
image = ImageIO.read(file);
}
catch(Exception ex){}
repaint();
}
browse.setVisible(false);
}
});
}

public void paint(Graphics g) {
g.drawImage( image, 0, 0, null);

}
public static void main(String[] args) {
JFrame frame = new JFrame("");
JPanel panel = new DisplayImage();
frame.getContentPane().add(panel);
frame.setSize(300, 300);
frame.setVisible(true);
}

}
class ImageFileFilter extends javax.swing.filechooser.FileFilter {
public boolean accept(File file) {
if (file.isDirectory()) return false;
String name = file.getName().toLowerCase();
return (name.endsWith(".jpg") || name.endsWith(".png")|| name.endsWith(".gif"));
}
public String getDescription() { return "Images (*.gif,*.bmp, *.jpg, *.png )"; }
}









Related Tutorials/Questions & Answers:
Images in java
Images in java  how to handle images in java
java mail sending with images
java mail sending with images  I need to send images through java mail without giving content path(i.e. we don't want hard code the image path)can you tell me the idea?   Please visit the following links: http
Advertisements
images - Java Beginners
images  how to do image watermarking in java? or how to identify watermarked images.. tell something related to the watermarking concept implementation in java?  Hi Friend, Try the following code: import java.io.
Sending images through java mail
Sending images through java mail  Am trying to develop greeting application that having images..... in one jsp page i displayed all images and by clicking one image the control go to mail sending page in that the image should add
images - Java Beginners
("Java"); content.add(button1); ImageIcon cup = new ImageIcon("/home...); content.add(button2); JButton button3 = new JButton("Java", cup..., http://www.roseindia.net/java/example/java/swing/ Thanks
Collision Detection between two images in Java
Collision Detection between two images in Java  Collision Detection between two images in Java
images
images  code for displaying image in java swings
Display Multiple Images in jscrollpane using Java Jpanel
Display Multiple Images in jscrollpane using Java Jpanel  Browse and Display multiple images in vertical view of java jscrollpane using jpanel
Version of com.applitools>eyes-images-java dependency
List of Version of com.applitools>eyes-images-java dependency
how to upload and download images in java?
how to upload and download images in java?  what is the code for uploading and downloading images in java? how do I make a photo gallery through JSP....   Upload and Download images: 1)page.jsp: <%@ page language="java
java collision detection between two images
java collision detection between two images  java collision detection between two images
compareing images using java - Swing AWT
compareing images using java  hi can u please give me the code in java to compare imges..i have the program to get the pixel values using pixel... with another image,i.e,program to compare two images using the pixel values.. thank
Maven Dependency eyes-images-java >> 2.34
You should include the dependency code given in this page to add Maven Dependency of com.applitools >> eyes-images-java version2.34 in your project
Maven Dependency eyes-images-java >> 2.49
You should include the dependency code given in this page to add Maven Dependency of com.applitools >> eyes-images-java version2.49 in your project
Maven Dependency eyes-images-java >> 2.50
You should include the dependency code given in this page to add Maven Dependency of com.applitools >> eyes-images-java version2.50 in your project
Maven Dependency eyes-images-java >> 2.51
You should include the dependency code given in this page to add Maven Dependency of com.applitools >> eyes-images-java version2.51 in your project
Maven Dependency eyes-images-java >> 2.53
You should include the dependency code given in this page to add Maven Dependency of com.applitools >> eyes-images-java version2.53 in your project
Maven Dependency eyes-images-java >> 2.54
You should include the dependency code given in this page to add Maven Dependency of com.applitools >> eyes-images-java version2.54 in your project
Maven Dependency eyes-images-java >> 2.55
You should include the dependency code given in this page to add Maven Dependency of com.applitools >> eyes-images-java version2.55 in your project
Maven Dependency eyes-images-java >> 2.56
You should include the dependency code given in this page to add Maven Dependency of com.applitools >> eyes-images-java version2.56 in your project
how to show set of images continously using JScrollpane in java
how to show set of images continously using JScrollpane in java  how to show set of images continously using JScrollpane in java
how to show set of images continously using JScrollpane in java
how to show set of images continously using JScrollpane in java  how to show set of images continously using JScrollpane in java
Maven Repository/Dependency: com.applitools | eyes-images-java
Maven Repository/Dependency of Group ID com.applitools and Artifact ID eyes-images-java. Latest version of com.applitools:eyes-images-java dependencies. # Version Release Date 1
Animating Images in Java Application
Animating Images in Java Application   ... with multiple images. You can see how animation has been implemented in the following... images. Image are given below: ADS_TO_REPLACE_1 In this program, images
displaying created images with java beans - Java Server Faces Questions
displaying created images with java beans  hello I am sorry I... am creating some images at "runtime" with an JSF application. without encountering any problem. But when I try to display these images during runtime, setURL
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp...;COLLEGE INFORMATION :</legend> <pre> Gallery Images: <input type... to upload the multiple images in struts Total images storing folder in project
displaying images created at runtime - Java Server Faces Questions
displaying images created at runtime  hello I am creating some images at "runtime" with an JSF application. I want this JSF application to display these images. But using only setURL displays nothing. do you have any
inked images
inked images  How do I eliminate the blue border around linked images
Moving The Images
Moving The Images  How to moving multiple images in one frame using swings
combining 5 images and text in between to one single image in java
combining 5 images and text in between to one single image in java  Hi I have to combine 5 images and text in between to one single image. I have image followed by description about the image. I have to put them together
images upload
images upload  I use netbeans IDE 6.8 How i upload any image from any folder to web page
Maven dependency for com.applitools - eyes-images-java version 2.56 is released. Learn to use eyes-images-java version 2.56 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.56. Developer can use this version ( com.applitools - eyes-images-java version 2.56
Maven dependency for com.applitools - eyes-images-java version 2.55 is released. Learn to use eyes-images-java version 2.55 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.55. Developer can use this version ( com.applitools - eyes-images-java version 2.55
Maven dependency for com.applitools - eyes-images-java version 2.53 is released. Learn to use eyes-images-java version 2.53 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.53. Developer can use this version ( com.applitools - eyes-images-java version 2.53
Maven dependency for com.applitools - eyes-images-java version 2.51 is released. Learn to use eyes-images-java version 2.51 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.51. Developer can use this version ( com.applitools - eyes-images-java version 2.51
Maven dependency for com.applitools - eyes-images-java version 2.50 is released. Learn to use eyes-images-java version 2.50 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.50. Developer can use this version ( com.applitools - eyes-images-java version 2.50
Maven dependency for com.applitools - eyes-images-java version 2.49 is released. Learn to use eyes-images-java version 2.49 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.49. Developer can use this version ( com.applitools - eyes-images-java version 2.49
Maven dependency for com.applitools - eyes-images-java version 2.34 is released. Learn to use eyes-images-java version 2.34 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.34. Developer can use this version ( com.applitools - eyes-images-java version 2.34
Maven dependency for com.applitools - eyes-images-java version 2.57 is released. Learn to use eyes-images-java version 2.57 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.57. Developer can use this version ( com.applitools - eyes-images-java version 2.57
Maven dependency for com.applitools - eyes-images-java version 2.54 is released. Learn to use eyes-images-java version 2.54 in Maven based Java projects
-java released The developers of   com.applitools - eyes-images-java..., the released version of  com.applitools - eyes-images-java library is 2.54. Developer can use this version ( com.applitools - eyes-images-java version 2.54
how to re size image proportionately using java for different images like jpeg, png, gif.
how to re size image proportionately using java for different images like jpeg, png, gif.  hi, i need sample code for re size image proportionately using java for different images like jpeg, png, gif, this code for my
jsp images
jsp images  hi I had done a demo application using jsp. And i tried to display some images which is located in the server folder. It has done by using the IP address path of that image folder.. It has been success full in IE

Ads