Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-05-2007, 04:41 AM
Member
 
Join Date: Jul 2007
Posts: 41
katie is on a distinguished road
how to save image as jpg?
I have made an application that reads a jpg image, manipulates it like a filter and exports the new data array to a MemoryImageSource and then to an Image.

How can I save this Image or MemoryImageSource to a legal image file such as Bmp, Jpg?
thanks in advance
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-05-2007, 08:37 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,022
hardwired is on a distinguished road
Code:
import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; public class SavingAnImage { public static void main(String[] args) throws IOException { String path = "images/cougar.jpg"; BufferedImage src = ImageIO.read(new File(path)); // Convert Image to BufferedImage if required. BufferedImage image = toBufferedImage(src); save(image, "jpg"); // png okay, j2se 1.4+ save(image, "bmp"); // j2se 1.5+ // gif okay in j2se 1.6+ } private static void save(BufferedImage image, String ext) { String fileName = "savingAnImage"; File file = new File(fileName + "." + ext); try { ImageIO.write(image, ext, file); // ignore returned boolean } catch(IOException e) { System.out.println("Write error for " + file.getPath() + ": " + e.getMessage()); } } private static BufferedImage toBufferedImage(Image src) { int w = src.getWidth(null); int h = src.getHeight(null); int type = BufferedImage.TYPE_INT_RGB; // other options BufferedImage dest = new BufferedImage(w, h, type); Graphics2D g2 = dest.createGraphics(); g2.drawImage(src, 0, 0, null); g2.dispose(); return dest; } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-06-2007, 04:32 AM
Member
 
Join Date: Jul 2007
Posts: 41
katie is on a distinguished road
you are very fast
thanks for everything
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to save image to disk after using pixelgrabber shishirg Advanced Java 3 04-17-2008 04:58 PM
How can i save the data Internally(auto save) Rama Koti Reddy AWT / Swing 0 12-10-2007 02:46 PM
Writing text into an image and save it elcapi Java 2D 2 07-11-2007 08:09 PM


All times are GMT +3. The time now is 03:46 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org