Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
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 11-22-2007, 07:29 AM
Member
 
Join Date: Nov 2007
Posts: 5
archanajathan is on a distinguished road
copy image/imageicon into a file on disk
I have created an imageIcon. I want to copy it into a file on the disk.


I have file on my disk (named : abc.jpg). I picked up the file and stored it in an imageicon using the code :

ImageIcon i=new ImageIcon("abc.jpg");


Then i did some processing on the imageicon "i" using the method :

ImageIcon process(ImageIcon)


The process method returned an imageicon which i stored into the variable "new_i" of type ImageIcon like this:

ImageIcon new_i=process(i);


Now i want to store this new_i ImageIcon into the disk (with named suppose : new_abc.jpg)


How do i do that?
Well, i tried it out after a lot of research in this way :

Image img = new_i.getImage();

BufferedImage bi = new BufferedImage(img.getWidth(null),img.getHeight(nul l), BufferedImage.TYPE_BYTE_ARGB );

ImageIO.write(bi, "jpg", new File("new_abc.jpg"));


The above code creates the file "new_abc.jpg" and just copies the structure of the image icon. From structure, i mean to say, it creates a black image with the size same as "abc.jpg".

If you can identify the mistake in the above code then please let me know. Or else if you know some other method for copying an image into a file, the please reply.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-22-2007, 07:55 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
Image img = new_i.getImage(); BufferedImage bi = new BufferedImage(img.getWidth(null),img.getHeight(null, BufferedImage.TYPE_BYTE_ARGB); Graphics2D g2 = bi.createGraphics(); // Draw img into bi so we can write it to file. g2.drawImage(img, 0, 0, null); g2.dispose(); // Now bi contains the img. // Note: img may have transparent pixels in it; if so, okay. // If not and you can use TYPE_INT_RGB you will get better // performance with it in the jvm. ImageIO.write(bi, "jpg", new File("new_abc.jpg"));
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-22-2007, 08:21 AM
Member
 
Join Date: Nov 2007
Posts: 5
archanajathan is on a distinguished road
hey thanks for the instant and correct reply...it worked.
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
Copy a .swf file from server side to client using signed applet Imoracle Java Applets 2 10-05-2008 08:13 PM
how to save image to disk after using pixelgrabber shishirg Advanced Java 3 04-17-2008 05:58 PM
Disk File System Access and Monitoring drveresh Advanced Java 1 07-03-2007 04:01 PM


All times are GMT +3. The time now is 11:38 PM.


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