• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

saving an image

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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");
}


}
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
conor murphy
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

thanks for that its working now

thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic