java image loadin and saving problem

java image loadin and saving problem

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
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
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
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
ModuleNotFoundError: No module named 'loadin'
ModuleNotFoundError: No module named 'loadin'  Hi, My Python... 'loadin' How to remove the ModuleNotFoundError: No module named 'loadin'... to install padas library. You can install loadin python with following command
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
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 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
jsp image problem - JSP-Servlet
jsp image problem  hi everyone, How to display multiple images from mysql database to jsp page. please help me
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
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 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
saving files
saving files  i want to create a program that would allows me to save my file and attach data
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
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
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... friend, Code to help solve the problem. Download Images
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
image compression - Java Beginners
image compression  image compression in java coding
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
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
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
resolution problem in java
resolution problem in java  I designed project in java in my PC when run the same project in some other PC i can't fully view my java forms.Some said that it is resolution problem
java image compression - Java Beginners
java image compression  image compression in java
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
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
java rotate image
java rotate image   How to rotate image to 90 and 180. can you please post an example to rotate image
java programming problem - JDBC
java programming problem  Hi, Request you to provide the source code in Java for the following programming problem : upload .csv file data into oracle database. please send the solution to [email protected]
image retrieve - Java Beginners
Image Retrieve  How to retrieve the image from mysql field using java
JSF image - Java Server Faces Questions
to save the image.Without saving i want to display the image in jsf page. public static Image createBarcode(String genCode) { Image image = null; try...); barCode.setData(genCode); image = barCode.makeSimpleImage(1, 35, true, 1
Problem in uploading java application
Problem in uploading java application  I have uploaded my java application (folder created under webapps) using Filezilla FtpClient.Application... this problem
for a problem in coading - Java Beginners
for a problem in coading  what is the problm in following coading...(String[] args) { mywindow (); } }   Hi Friend, There is no problem... mywindows.java Run : java mywindows Thanks RoseIndia Team
image display - Java Beginners
image display  i need to display all the images from the folder and i dont want give the image path.dynamically it should display. please help  Hi friend, Code to help in solving the problem var
Multiplication problem - Java Beginners
Multiplication problem  I am facing a peculiar problem in java regarding a multiplication. Please see below: 19300 * 0.001 = 19.3 19400 * 0.001 = 19.400000000000002 (why is this ??) 19500 * 0.001 = 19.5 Can anybody help
java input problem - Java Beginners
java input problem  I am facing a Java input problem
code problem - Java Beginners
java script j2ee j2me sql plz help me to sort out this problem. thnx  ...code problem  Dear sir, I'm havin a problem that suppose i've got a file that contains the following lines- java java script j2ee php sql
Java- Save Image into project folder in web application
Java- Save Image into project folder in web application  I have a requirement of saving the image into project folder .. which is a web application... want to save the image..when I am trying to create empty folder and get
Problem on JAVA Programme
Problem on JAVA Programme  public class AA { int add(int i) { int y = i; y += 20; if (y <= 100){ y +=30;add(y);} System.out.println("Final Value of y : " + y); return y; } public static void main
JAVA CLASSPATH PROBLEM
JAVA CLASSPATH PROBLEM  hi all Friends I am stuck using the java servlets and problem raise for classpath. I had a problem with servlet to call... that it didn't found any java class (which is java class calling from servlet). but i
java image display - Java Beginners
java image display  How to display images in the folder dynamically with out using database using java and jsp  Hi friend, Code to help in solving the problem var galleryarray=new Array
java programming problem - JDBC
java programming problem  Hi, Request you to provide a solution... problem to the following mail id : Problem : upload excel file data into oracle database using java / j2ee. mail id : [email protected]
Problem with picture - Java Beginners
Problem with picture   Hi, I Develope a School Automated System that takes a details from the user interface and deposited into the database...; Hi Friend, To upload and insert the image into database, try the following
Image using Java coding
Image using Java coding  Hai, Display image in pdf file using Java coding through Xsl file.. Please help me.. xsl file generate the pdf file
Java Problem - Java Beginners
Java Problem  Write a program 2 input a positive integer n and check wheter n is prime or not and also know the position of that number in the prime..., Code to solve the problem : import java.io.*; public class PrimeNumber
Java Image Browsing Applet
Java Image Browsing Applet  Hi. I want to create an applet which is embedded in html page which display image by browsing the files in the computers hard disk... Please help me out
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 implementation problem
/answers/viewqa/Java-Beginners/28578-java-implementation-problem-.html...Java implementation problem  I want to implement following in java... problem in your post previews. please consider 1. 2. points just after main

Ads