Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

saving an image  RSS feed

 
conor murphy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

i am trying to save an image that i have in a JLabel as a jpeg file. i am able to load the image as an ImageIcon and then add it to a label but when i try to save it using ImageIO.write() it just turns the whole thing black. would someone please be able to tell me wat im doing wrong.

thanks

try{

//open file dialog box
Frame frame = new Frame();
FileDialog fd = new FileDialog(frame, "Save File", FileDialog.SAVE);
fd.show();

//retirve the path
path = fd.getDirectory();

//retrieve the filename
filename = fd.getFile();

//add the filename and path together
filename = path + filename;

BufferedImage bi = new BufferedImage(im.getIconWidth(),im.getIconHeight(),BufferedImage.TYPE_INT_RGB);

ImageIO.write((RenderedImage)bi, "jpeg", new File(filename));

}
catch(IOException e) {
// Print out the exception that occurred
System.out.println("Unable to Save");
}


}
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
conor murphy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

thanks for that its working now

thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!