Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Shahnawaz qadir
Images in java
2 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners


how to handle images in java


Advertisement
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.
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
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
images  code for displaying image in java swings
Collision Detection between two images in Java
Collision Detection between two images in Java  Collision Detection between two images in Java
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
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
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
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
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
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: In this program, images are displayed one
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
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
Moving The Images
Moving The Images  How to moving multiple images in one frame using swings
inked images
inked images  How do I eliminate the blue border around linked images
images upload
images upload  I use netbeans IDE 6.8 How i upload any image from any folder to web page
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
How To Store Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
How To Store Multilple Images In MySQL database dynamically with image... Multilple Images In MySQL database dynamically with image uploader and then retrieve them in image gallery using java
 

 

 

DMCA.com