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



Home Answers Viewqa Swing-AWT java image loadin and saving problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Poonam
java image loadin and saving problem
1 Answer(s)      5 years ago
Posted in : Swing AWT



Advertisement
View Answers

November 11, 2009 at 2:27 PM


Hi Friend,

Use the following code:

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

public class SaveImage extends Component {
int index;
BufferedImage bi, bufferImage;
int w, h;
static JButton button;

public SaveImage() {
try {
JFileChooser chooser = new JFileChooser();

bi = ImageIO.read(new File("node.jpg"));
w = bi.getWidth(null);
h = bi.getHeight(null);
if (bi.getType() != BufferedImage.TYPE_INT_RGB) {
BufferedImage bi2 = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
Graphics big = bi2.getGraphics();
big.drawImage(bi, 0, 0, null);
bufferImage = bi = bi2;
}
} catch (IOException e) {
System.out.println("Image could not be read");
System.exit(1);
}
button=new JButton("Save");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
File saveFile = new File("image." + "jpg");
JFileChooser chooser = new JFileChooser();
chooser.setSelectedFile(saveFile);
int val = chooser.showSaveDialog(button);
if (val == JFileChooser.APPROVE_OPTION) {
saveFile = chooser.getSelectedFile();
try {
ImageIO.write(bufferImage, "jpg", saveFile);
} catch (IOException ex) {
}
}
}
});
}
public Dimension getPreferredSize() {
return new Dimension(w, h);
}
public void paint(Graphics g) {
filterImage();
g.drawImage(bufferImage, 0, 0, null);
}
public void filterImage(){
BufferedImageOp op = null;
switch (index){
case 0:
bufferImage = bi;
return;
case 1:
}
bufferImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
op.filter(bi, bufferImage);
}
public static void main(String s[]) {
JFrame f = new JFrame("Save Image");
SaveImage si = new SaveImage();
f.add("Center", si);
JPanel panel = new JPanel();
panel.add(button);
f.add("South", panel);
f.pack();
f.setVisible(true);
}
}

Hope that it will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
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
Error in laodin and saving the image . - Swing AWT
facing problem while laoding and saving the image with help of JFileChooser class...Error in laodin and saving the image .  I am a student who had... class UploadImage extends JPanel { static BufferedImage image; static File
Advertisements
Saving image and text in mysql db using spring?
Saving image and text in mysql db using spring?  Hii, My requirement is to save the employee details(including image) into mysql db.i want to save the image location in db .And actual image(binary formate) should save
j2me image problem - Java Beginners
j2me image problem  hi, i am new for j2me programs. i created image using canvas class. i want to change the image. i have no idea about it. please help me. thank u in advance. regards, sakthi.s  Hi Friend
jsf image problem - Java Server Faces Questions
jsf image problem  Dear Sir My doubt is about displAying... bean i want to display that image contained in that object to the jsf page.This image is not physically stored in the local disk.I tried out by using the jsf
Saving URL in local disk - Java Beginners
Saving URL in local disk  Hi Friend, How can i Save URL like "www.jagran.com " on local disk throgh java Statement. Thanks ,in advance
Having problem with image upload....
Having problem with image upload....  I am uploading profile pictures... that the image is getting uploaded.I also right clicked on the home page... of the image absolutely correct.But when I click on the url it is saying requested
Problem in uploading image to to mysql database
have no problem in saving the image in the folder, my problem is it can't save...Problem in uploading image to to mysql database  Hi, need some help here, i have a program where a user can input name, city and upload image. when
Problem in uploading image to to mysql database
have no problem in saving the image in the folder, my problem is it can't save...Problem in uploading image to to mysql database  Hi, need some help here, i have a program where a user can input name, city and upload image. when
Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same
Java code for Saving Marathi (Indian local language ) in Mysql and retrieving the same  Hello , My query got solved. Thnx.I am right now... java using eclipse but after saving it shows " ???? " in place of marathi words
Image problem Urgent - JSP-Servlet
Image problem Urgent  Respected Sir/madam, I am R.Ragavendran.. Actually I got your coding.. But This code is not enabling the user to click and change the image.. I request you to remember the code which you have
saving files
saving files  i want to create a program that would allows me to save my file and attach data
image effects - Java Beginners
image effects  hey can u help me in loadin an image file... that will show you image crop effect: import java.sql.*; import java.awt.... java.awt.image.FilteredImageSource; public class Upload extends JPanel { BufferedImage image; Image img
jsp image problem - JSP-Servlet
jsp image problem  hi everyone, How to display multiple images from mysql database to jsp page. please help me
Saving data in database
Saving data in database  hello i m facing a strange problem if i am submitting data form database then i can see it in database but if am submitting from app then it is not showing in to database but when i fetching form
problem to do coding upload image in php
problem to do coding upload image in php  can i get example coding how to upload image in php?i have try it but i dont no wheter it is correct or not because i can't save the image in folder and not connected to database mysql
image compression - Java Beginners
image compression  image compression in java coding
image upload in java
image upload in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open dialog box to select image, it will work properly i.e on button click open dialog is open
image save to folder in java
image save to folder in java  Hi, I am working with java. In my application i want to give facility to user to add and change image. I use open dialog box to select image, it will work properly i.e on button click open dialog
java image compression - Java Beginners
java image compression  image compression in java
Image Processing Java
://www.universalwebservices.net/web-programming-resources/java/adjust-jpeg-image-compression-quality-when-saving-images-in-java */ public class DemoJPEGCompression...Image Processing Java  Using This Code I Compressed A JPEG Image
java rotate image
java rotate image   How to rotate image to 90 and 180. can you please post an example to rotate image
image - Java Beginners
image  how to identify the watermarked image? or how to convert the watermarked image into original image? can you send that corresponding java code
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
saving data in xml
saving data in xml  Hi, I have an xml file with spring map, in that i have parent child nodes. I have jsp form in that i have put same parent child elements. when i submit jsp form I want to append same data into xml file
Java problem - Java Beginners
Java problem  I have an image in my application and I need to restrict the image path view on the browser. Noone should be able to right click and see the image path. Please help
java Problem
java Problem  I want to create a binary tree for displaying members in Downline. i am creating a site for MLM(Multi-Level MArketing). tree must be dynamically populated from database. is there any help for me. Thanks in advance
JAVA Problem
JAVA Problem  Write a program that takes two parameters 1. a word 2. an array of words It should then remove all instances of the word in the array. For Example: INPUT word="ravi" word_array = ["Chethan Bhagat
File saving and Writing
File saving and Writing   Hello Rose india..... I have a doubt for you plzzz kindly Help me... I have an "Arraylist" which includes some table values... What i want to ask is "I want to create a jsp page which will include
Converting HTML to image - Java Beginners
Converting HTML to image   Is it possible to convert html to image with java code ?   Hi friend, Please give the problem in details...://www.roseindia.net/java/ Thanks
preview and saving an application form
preview and saving an application form   i have developed an application form, which is to be filled by the user.That application form is big in size so i have splitted that application form in 6 different forms ie, in first jsp
 

 

 

DMCA.com