• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic