New Image saving problem

Hi,
I have to write some things to a servlet (extends HttpServlet) as well as to draw images and save as gif to be displayed in the servlet.
I have accomplished up to generating a file, but the file is 0kb. Can anyone give me a suggestion?
These are the methods I am using:
public  static void saveGIF(OutputStream os) throws IOException {
       //Create an image to save
       int w = 100;
       int h = 100;
       BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
       Graphics2D g2 = image.createGraphics();
       g2.setPaint(Color.BLUE);
        g2.fillOval(0, 0, w, h);
       g2.dispose();
       ImageIO.write(image, "gif", new File("rect.gif"));
       display(image);
static void display(BufferedImage im) {
        JFrame f = new JFrame("Image");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JLabel(new ImageIcon(im)));
        f.pack();
        f.setLocationRelativeTo(null);
        f.setVisible(true);
     I have declared OutputStream ops;And I am calling saveGIF(ops) in the doGet method of the servlet.
Any suggestions or feedback is welcome.
Thank you.

Firstly, Erik44's post is wrong, your buffered image is ok.
Do you know that:
ImageIO.write(image, "gif", new File("rect.gif"));returns a boolean which is "false if no appropriate writer is found." Hmmmm. Add did you know the the jdk
is shipped with a reader but no writer for GIF format. Hmmmmm. Try jpeg or png format:
booleam writerFound = ImageIO.write(image, "jpeg", new File("rect.jpeg"));
if (!writerFound) {
}

Similar Messages

  • OMG! Another image saving problem, hope you will help me:)

    Hi there, I just found out that Java Console says:
    Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.io.FilePermission slika.jpg delete)
         at java.security.AccessControlContext.checkPermission(Unknown Source)
         at java.security.AccessController.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkPermission(Unknown Source)
         at java.lang.SecurityManager.checkDelete(Unknown Source)
         at java.io.File.delete(Unknown Source)
         at javax.imageio.ImageIO.write(Unknown Source)
         at postavka.snimi_sliku(postavka.java:76)
         at postavka.actionPerformed(postavka.java:101)
         at java.awt.Button.processActionEvent(Unknown Source)
         at java.awt.Button.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    when I'm trying to save an "slika.jpg" file from my aplet image;
    What does it mean people? Why cant I save my images?

    Your doing this through an applet ?
    Welcome to the wonderful world of permissions
    http://java.sun.com/docs/books/tutorial/security/tour1/index.html

  • Colour profiles problem - images saving too dull. Please help.

    I realise you have probably had this question a million times before and I have looked at enough related threads, but I am still at a loss as to what to do. Please note I'm not the most computer-savvy.
    For the record I am using Photoshop 7 (yes it's old, but it suits my needs just fine!) and Windows Vista Home Premium.
    What I do is take photographs of my artworks, edit them in Photoshop until they look accurate, then post them online. Images have always looked identical in every program, and I had never had any problems, until I got connected to the Internet on Tuesday. This computer has not been connected to the net for a good few years, and so lots of updates got installed. I'm not sure which ones exactly, as my boyfriend took care of that, but I'm convinced this has caused the problems I am having now:
    First I found that an image I had edited and saved as .jpg for web use was showing up overly saturated and contrasty in the Windows Photo Gallery preview. I assumed I had saved it wrongly. I re-opened the jpg in Photoshop to check - it looked exactly as I had saved it. I figured something had messed up with Photo Gallery during updates, so I uploaded the jpg to the Internet. The image that uploaded was the overly-saturated, contrasty one.
    After realising that suddenly ALL the images I had uploaded online, and all the images saved on my computer, now had this awful over-saturated look, and yet the thumbnails on my desktop looked fine... I realised it must be something to do with the colour profiles, and tried to find out the answer online. My monitor colour profile was set to "21.5 inch monitor" so I changed that to sRGB as default. I can't remember what Photoshop was set to, but at any rate I set it to sRGB also.
    I thought I had it fixed, as it seemed to just be Photo Gallery that was not matching up (it was displaying my images with less saturation than as I saved them).
    However today I took a new photo of a drawing I'm working on, to load onto my blog. I had to take it into Photoshop to make edits and correct, as always. I opened my photo in Photoshop... lo and behold, far too contrasty and saturated!!
    This time, Windows Photo Gallery preview is showing the (unedited, straight out of camera) photo as it should be... Photoshop opens it too contrasty.
    I made my edits anyway, saved for web as .jpg, checked the jpg in Photo Gallery before uploading... It saved duller than it should have done!
    Uploaded the jpg to the internet... and I have the dull image uploaded.
    So first they were too contrasty, now they're too dull. I have tried to follow advice given on similar topics, to no apparent avail.
    Being an artist who displays work online and has a certain reliance on the internet... my images have to be accurate and consistent all the way through. Is there anything I can do to set things back to the way they were before?
    I appreciate any help.

    eartho - All my images are already converted to the sRGB colourspace by default, as far as I can tell. My images out of camera, the ones I have edited and saved as jpg - I even checked some old images. Through Mode/Convert to Profile, they're all already set to sRGB.
    emil emil - Thank you. I will do that in the morning - right now my head hurts and I need my bed.

  • How can I add new images to a saved book in Lightroom 4? Help please!

    As the title suggests, I have created a saved book in LR4. I saved it not because I had finished but because I wanted to protect my work to date. Now I cannot add new images, although I can work with (move and remove) the exisintg images in the book.
    I'm new to LR and can't help but feel that I'm missing something obvious. Any advice would be greatly appreciated!
    Thanks
    Graham

    Graham, switch to Grid view and drag the new photos to the book collection, which you'll find in the Collections panel.  Then flip back to the Book module and you'll find the photos sat there in the Filmstrip waiting to be added to the book design.

  • Can't create a new illustration. Problems occurred while saving the print file.

    I can't open a new Illustrator file. It sends me this error: Can't create a new illustration. Problems occurred while saving the print file. ID:-1
    I opened a previous document created in CC, but it will not allow me to copy and paste items from one doc to another.
    I have rebooted with no avail.
    System:
    Adobe Creative Cloud CC
    Mac Book Pro 2012
    2.6 GHz Intel Core i7
    8 GB 1600 MHz DDR3

    Is a printer connected? Is it turned ON? Is the driver up to date?
    Illustrator checks this every time and also writes information on the printer into the file.

  • Problem setting a new image to be displayed in JScrollPane

    Hi everyone,
    I'm having a problem with an image retrieval application I'm developing and basically the problem is when I run the application and search for an image, the image is found and displayed fine on screen using an instance of DisplayJAI (from the JAI packages). However, when I search for another image it clears the old image fine but doesn't display the new one. I though it might be a repaint issue because the SQL is correct but it simply clears the scrollPane of content and doesn't update it with the new image. Has anyone ever come across this problem before or have any ideas? Any help would be much appreciated, thanks.

    This is fixed by turning off the optimization..

  • I am using referenced images, saved on an external hard drive. It would be most helpful to transfer the new captions (version name) to the referenced images which still have the camera code on them. How can this be done? Thanks so much!

    I am using referenced images, saved on an external hard drive. It would be most helpful to transfer the new captions (version name) to the referenced images which still have the camera code on them. How can this be done? Thanks so much!

    You're question is hard to follow. Are you looking to rename your master files to the version name? Or are you looking to do something with IPTC caption field and the masters?

  • DISK UTILITY -- "New Image" problems

    Maybe I don't get how this works. I used an external USB drive to back up my MacBook Pro, making an image un=sing Disk Utility "New Image." THis seems to have worked fine. When I attach the external drive and double click on the DMG file it open and I seem to have access to all contents.
    Today I tried to make a second "New Image" on the same drive of my iMac24" and everything runs and makes a DMG file, but when I click on this one I get a msg saying the disk image "couldn't be opened" with the reason given being "no mountable file systems."
    Does this make perfect sense to somebody?
    Have I completely misunderstood the use and practice of the "new image" in Disk Utility?
    Thanks.

    Hey. If you want to make a DMG image of your iMac, you will need to boot off the install DVD and use Disk Utility from the DVD. To create the DMG is the same process: Select the "Macintosh HD" icon on the left hand side list of Disk Utility, click the "New Image" button, leave "Image Format" as "Compressed" and its up to you for Encryption, I always leave it as "None".
    Select to save your DMG image on the external hard drive and click save. Once the image is done, click on "Image" on the menu bar and click on "Scan Image for Restore...".
    That's it!
    Good luck

  • I don't want Firefox to "remember" the folders I've saved in from websites before. How do I return Firefox to its old image saving habits?

    I recently got a new computer and upgraded to Firefox 8. Now, when I save an image from a website, Firefox will "remember" and, the next time I save an image, open a random folder that I saved an image in last time I was on that site, and choose to save it there. This wouldn't be a problem if, 1) it wasn't a random folder out of the several I save into, and 2), if I have to cancel out of an image for any reason, the next time I go to save (seconds later, without refreshing/leaving a page), it will have chosen another random folder for me to save in and I'm misplacing my files.
    I'd like to return Firefox to the previous image saving habits, where I have to choose the folder each time, and it doesn't "remember" anything that I've done, as it is only causing headaches.

    I have been frustrated by the same aggravating Firefox 8 "improvement".
    I have several hard drives, several partitions on each hard drive, hundreds of folders on in each partition, and hundreds of subfolders below them. When I am researching something, I download whole Web pages, PDFs, JPEGs, FLVs, and many other files from all over the Web. It is totally frustrating to be taken to different drives all over my computer each time I want to download a new file to the same folder I jut downloaded to. I have to drill up and down drives and folders to get back to where I was.
    In previous versions of Firefox, Save As opened in the last folder I saved to, and all I had to do was create a file name and hit Save. In Firefox 8 I am taken to some totally unrelated subfolder on some totally unrelated drive. The folder in which I last downloaded a file from Wikipedia, Fox News, BBC , Flicker, or any other URL usually has absolutely nothing to do with what I am presently researching.
    Why would anyone want to make the default download be the desktop? Total clutter and confusion. All I want Firefox to do when I hit the Save As button is to open the same folder I last downloaded '''''anything''''' to irregardless of the URL.
    Is there some way via modifying the about:config file that I can change this behavior of Firefox 8?

  • Bizarre image load problem in InDesign CS2

    Hi, I am having a problem with bringing in some images into InDesign CS2. I have a document file that has many images in place, and I just received some new images that are screenshots from video. They are saved as rgb jpgs. They are 2700x1963 pixels and 300dpi (so someone obviously did some conversion from screen res.)
    When I try to bring them into an image box in InDesign, I do command D, then select the image. It acts like its loading it but then nothing is in the box. I thought perhaps the image was just hidden outside of the edge of the box but when I go to "fitting" under the "OBJECT" menu, all the options are greyed out as if there is no image there. It also shows no image linked in the links panel.
    I tried opening in photoshop and resaving, and also tried resaving as another name. I tried changing it to cmyk and adjusting the levels and resaving as tif. I tried making a new photoshop file and copy-and=pasting the image into it and saving. Still, no image will load in the image box.
    I feel like the images must have corrupted since they were sent to me as email attachments, but its so odd that they open in photoshop just fine. Any ideas?

    nevermind, people.
    my computer was having memory overload. on a whim I restarted the computer.
    BAM...no issue.
    You know what they always say, "When all else fails, restart your computer!"

  • Images saved by Firefox randomly corrupt? (FF 6.0.2 and 5.0.1)

    I've noticed this issue for quite some time. Using Windows XP, images saved from the Internet (right click method) will randomly corrupt. When browsing the thumbnails, certain ones will display a generic JPG icon rather than an actual thumbnail, and the picture cannot be viewed by any software. I'm running FF 5 on a netbook and FF 6 on my desktop system, and BOTH computers are having this issue. The only thing in common here is that Firefox is the browser doing the work. Any idea what could be the problem?

    If there are problems with updating or with the permissions then easiest is to download the full version and trash the currently installed version to do a clean install of the new version.
    Download a new copy of the Firefox program and save the disk image (dmg) file to the desktop
    * Firefox 7.0.x: http://www.mozilla.com/en-US/firefox/all.html
    * Trash the current Firefox application to do a clean (re-)install
    * Install the new version that you have downloaded
    Your profile data is stored elsewhere in the Firefox Profile Folder, so you won't lose your bookmarks and other personal data if you uninstall and (re)install Firefox.
    * http://kb.mozillazine.org/Profile_folder_-_Firefox

  • Need to save the image saved in the System Clipboard in using JDK 1.3.1

    Does anyone know how to use JDK 1.3.1 to take an image saved in the System clipboard and save it to a file using the JPG format?
    I know how it is done in JDK 1.4 using the following code. Unfortunately, the same code does not recognize the image in the clipboard in JDK 1.3.1
    I am using jai-1_1_2_01.
    package clipboard;
    import java.awt.datatransfer.Clipboard;
    import java.awt.datatransfer.DataFlavor;
    import java.awt.datatransfer.Transferable;
    import java.awt.image.RenderedImage;
    import java.awt.Toolkit;
    import java.awt.datatransfer.UnsupportedFlavorException;
    import java.io.IOException;
    import java.io.FileOutputStream;
    import java.io.BufferedOutputStream;
    import java.io.File;
    import javax.media.jai.JAI;
    import javax.media.jai.RenderedOp;
    public class clipboard
    {  private File tempFile = null;
    * @param args
    static int BUFFER_SIZE = 65536;
    public static void main(String[] args)
    {  clipboard clip = new clipboard();
    clip.writeImageFromClipboard();
    public void writeImageFromClipboard()
    {  Clipboard            clip = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable transferable = clip.getContents(null);
    RenderedImage img = null;
    FileOutputStream fileOutStr = null;
    BufferedOutputStream bufOutStr = null;
    DataFlavor [] dataFlavors;
    File tempFile;
    int
    byteCount;
    String [] strArr;
    dataFlavors = transferable.getTransferDataFlavors();
    System.out.println("clip=" + clip.getName());
    System.out.println("Transferable=" + transferable);
    for (int i = 0; i < dataFlavors.length; i++)
    {  System.out.println("dataFlavours[" + i + "]=" + dataFlavors.toString());
    if (transferable.isDataFlavorSupported(new DataFlavor("image/x-java-image; class=java.awt.Image", "Image")))
    { try
    { img = (RenderedImage) transferable.getTransferData(new DataFlavor("image/x-java-image; class=java.awt.Image", "Image"));
    if (this.tempFile == null)
    { this.tempFile = File.createTempFile("__TMP_IMG__", ".jpg");
    System.out.println(this.tempFile.getCanonicalPath());
    fileOutStr = new FileOutputStream(this.tempFile);
    bufOutStr = new BufferedOutputStream(fileOutStr);
    // Encode the file as a JPG image.
    JAI.create("encode", img, bufOutStr, "JPEG", null);
    catch (UnsupportedFlavorException e)
    { e.printStackTrace();
    catch (IOException e)
    { e.printStackTrace();
    finally
    { if (bufOutStr != null)
    { try
    { bufOutStr.flush();
    bufOutStr.close();
    catch (IOException e)
    if (fileOutStr != null)
    { try
    { fileOutStr.flush();
    fileOutStr.close();
    catch (IOException e)
    else
    { System.out.println("Not an image!");

    The login  you connected to the server  and run the above statement does not have permissions to operate  on this path "C:\Users\ISLLCdba\Desktop\MAA
    PROFILE PICTURES\"
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • No "before new record saved" trigger event in workflow definition ?

    Hello,
    I have following problem: I have to make a simple integration, where products have information about available quantity of given product . Assume we have field - it is called "Available amount" and it tells how many products are on stock. Now suppose we have created an opportunity, and we want to add Opportunity Product Revenue - we're selecting product and then quantity. I want to make OCOD to display message and prevent from adding opportunity product revenue, when its quantity is greater than "Available amount" field which is present in associated product record. I've created small C# application and used workflows to create Integration events. It works - but not exaclty how I want it - when I add a new record the workflow generates integration event - but I'd like to generate integration event before a record is created, also I'd like to show a notification from OCOD. But for "revenue" we do not have a trigger event called for example : "before new record saved" - we have only "when new record saved" and "before modified record saved".

    Hi,
    From your requirement, it seems you, want some kind of check. Did you try puting this validation on field level, i guess you would need to join fields and compare in field validation. So, whenever user creates a new record this validation kicks and user is notified of the error.

  • I have LR5 on a mac book pro with a external hard drive with LR5 images. my problem is my external hard corrupted reformatedand have to this is expensive and i would to start over in LR5

    i have LR5 on a mac book pro with a WD external hard drive with my with my LR5 images . my problem is my external drive is corrupted .i was told by apple that my macshow the hard drive is there but it is not moumting and have to be reformat. i have to use recovery data to save my images on my external before i can refomat.iam willing to lose my images on my extenal hard drive but i would like to know can i erase my LR5 images and start over or delete LR5 and download it again

    Simply start a new catalog:
    File >> New Catalog
    Choose a new name and save.
    When the empty catalog launches you are ready to start over.

  • My iMac 27" Late 2012 has Image Persistence Problem

    I'm wondering what to do about an annoying image persistence problem on my 27" late 2012 iMac. I got the iMac just a few days ago. Monday actually, so 4 days ago.
    It's the 3.4GHz i7, 8GB, NVIDIA 680MX 1TB fusion drive model.
    Overall it has become the love of my life, but the image persistence thing is getting harder to ignore. This happens after only a few minutes of use. If I follow Apple's instruction on dealing with LCD image persistence, I can make it go away for a while, but it comes back very quickly.
    It is extremely noticeable on a plan dark background. It looks as thought he screen has been left on for a very long time with the same windows open, but it occurrs in less than 5 minutes of use with nothing more intense than a bit of web surfing.
    I've read that this is happening a great deal on these new iMacs, particularly teh 27" machines.
    While the problem seems to be known to those of us afflicted I don't know if Apple has acknowledged an issue or not.
    Here is a sample of the complaints: http://forums.macrumors.com/showthread.php?t=1509571
    I can make the ghost image vanish by bringing up an all white scree for a minute or so or using LCD Scrub.
    I'm wondering if anyone else has foun a solution other than asking for a replacement computer, which Apple seems to be granting on this issue?

    Avoiding image persistence on Apple (IPS) displays
    Avoiding image persistence on Apple LCD displays
    If you cannot resolve the issue yourself, then return the computer for a replacement. You may do this freely within 14 days from date of purchase, so don't delay.

Maybe you are looking for

  • I, and my clients, want a VERY simple contact form hosting option...

    There's no need for us to have data collected and analyzed. No need for yet another hosting service to store data we'll NEVER use. I've already got a hosting service for my site. My clients already have hosting for their sites. None of us are willing

  • Stock Transfer PO

    I need some help on Stock Transfer Purchase Order? and could you pls expain me step by step, with t.codes? what type of Movement types we used? pls give me in details. thanks

  • ITunes 5 and 1st sync

    After I installed v5 I synced my iPod as normal however it "updated" 32 seemingly un-related tracks. Anyone else have this problem?

  • Mastering HD?

    Hello Forum I am finishing up a 25 minute project. I edited it in HD with the ProRes LT codec. We might go to tape in a few months for broadcast but in the meantime I just wanted to master the project as a file. I have tried to export it as prores 44

  • CS6 update (bug fix)

    I downloaded the latest AICS6 bug fix, just released. Not sure what it fixed, but the same old bug is there that I've been complaining about for over a year. Still can't drag global colors between sliders in gradient. The more things change the more