Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2009
    Posts
    34
    Rep Power
    0

    Default Error in saving an Image????

    I try to save an image but it does not work...

    try{
    jLabel3.setIcon(new ImageIcon(zoomOut(ProcessingImages.tmpSideA,8)));
    jLabel3.setText("");

    javax.imageio.ImageIO.write(ProcessingImages.tmpSi deA, "tstSideA", new File("d:\\yourImageName.JPG"));
    }
    catch(Exception e){
    e.printStackTrace();
    }

    I wrote above code to save the image when clicking a button. Then the first line executed and image displayed in jLabel3 as it supposed. zoomOut() is used just to reduce the size in 8 times.

    In D drive a image file of size 0bytes created but when it clicked to open there were a message displaying
    "Windows photo viewer cannot open the file because file is empty"

    I hope you could explain me how to correct the error....
    Thank you....
    Last edited by LankanSniper; 11-06-2009 at 07:38 AM.

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Looking up the method in the ImageIO class api
    Java Code:
    static boolean write(RenderedImage im, String formatName, File output)
    we see that the second argument is a format name.
    Try using "jpg" instead of "tstSideA".

  3. #3
    Join Date
    Mar 2009
    Posts
    34
    Rep Power
    0

    Default

    Thank you for your answer.. It works... But now i got a another problem... Size of the image I browse for the system was 1.83MB but when it saved to the hard disk with out any modification size reduce to 503KB. Which means it reduces the quality.. Since my target is to develop Character Recognition System it is necessary that the image should be in high quality.

    Therefore is there any way i can get the original size of the image file when saving to the hard disk????

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    The jpg format is lossy, ie, it uses compression.
    Try the png format; it is supposed to preserve everything.

  5. #5
    Join Date
    Mar 2009
    Posts
    34
    Rep Power
    0

Similar Threads

  1. Uncaught error fetching image
    By Manfizy in forum New To Java
    Replies: 9
    Last Post: 12-03-2011, 05:16 PM
  2. Saving image to sever.
    By dudejonne in forum New To Java
    Replies: 5
    Last Post: 11-03-2009, 03:01 PM
  3. error encountered when writing image file
    By angelinehelena in forum Advanced Java
    Replies: 1
    Last Post: 02-10-2009, 11:08 AM
  4. [SOLVED] Image drawing, saving
    By Goseph in forum Java 2D
    Replies: 2
    Last Post: 12-21-2008, 08:36 PM
  5. error while loading the image from the server
    By testtest in forum CLDC and MIDP
    Replies: 1
    Last Post: 09-23-2008, 06:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •