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




Have Programming Question? Ask it here!
 
 
 


Shahnawaz qadir
Images in java
2 Answer(s)      a year and 7 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
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
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
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
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array
how insert multiple images in mysql database with use of struts 1.3.8 or java method, with single bean,or using array  i am using netbeans 7.0 ,with struts 1.3.8 and i want to insert multiple images in mysql database ,with use
insert images into a Mysql database
insert images into a Mysql database  How can I insert images into a Mysql database
HTML background images
HTML background images  How can I specify background images
uiscrollview add images
uiscrollview add images  How to add dynamic images to UIScrollView
Displaying images - JDBC
Displaying images  How to display multiple images on a single jsp from MySql database
Displaying images - JDBC
Displaying images  How to display multiple images on a single jsp from MySql database
background images in css not working
background images in css not working  In the application i'm passing a background image from CSS in the given format ... background-image: url... of adding background images in css
Blob images - JSP-Servlet
Blob images  Hi sir how can i retrieve blob images from database using jsp from mysql  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/retrieve-image.shtml Hope that it will be helpful
Adding images in itext pdf
Adding images in itext pdf  Hi, How to add image in pdf file using itext? Thanks   Hi, You can use following code: PdfWriter.getInstance(document,new FileOutputStream("imagesPDF.pdf")); Read more at Inserting
upload images - JSP-Servlet
upload images  How to write the jsp code to upload images into database.   Hi Friend, The link we have provided you will allow you to upload any file therefor it can also upload an image and can insert
regarding images in jsp
regarding images in jsp  Hi, When I am trying to display an image in jsp, i am getting the image of bar charts in webroots/jspchart/web/jspbarchart.jsp.. But actually I am not getting any image in the browser.. Can any one help
need photoes,images - JavaMail
need photoes,images  hi this is nagarjuna. i need james binary server2.3.1 architecture. and i dont know about how it works. i have to give one seminar on mailing technology. so pls send the gif images,and some
JList Background Images..Urgent
JList Background Images..Urgent  I has done a JList that can change background color when i selected each of it, but if i want to change background image rather than background colors, how can i do it? Please help! my previous
WHAT TYPES OF IMAGES THAT PHP SUPPORTS?
WHAT TYPES OF IMAGES THAT PHP SUPPORTS?  WHAT TYPES OF IMAGES THAT PHP SUPPORTS
how to space images in html code
how to space images in html code  how to space images in html code
how to display multiple images on browser
how to display multiple images on browser  i want to display multiple images on brower including string values from sql database using jsp
how to display multiple images on browser
how to display multiple images on browser  i want to display multiple images on brower including string values from sql database using jsp
space around/between my images
space around/between my images  How do I eliminate the space around/between my images
get images from web service
get images from web service  How to get images from web services in iPhone application?   to get images from web service xml? For Uploading NSString *encodedString=[self encode:(const uint8_t*)_secretData.bytes
 

 

 

DMCA.com