Directly saving an image to a file?

Greetings. I blundered around a bit and managed to acquire an image by using the BufferedImage class and save it with the ImageIO.write method. But the thing is, I'd like the image to be saved without being recompressed so that the resulting image file is a 1:1 copy of what I started with.
If someone says "why not just copy it then" - I'm retrieving the image via ImageIO.read(url) from the web, so I can't just copy it. (erh... or can I?)
digiro

If someone says "why not just copy it then" - I'm
retrieving the image via ImageIO.read(url)
from the web, so I can't just copy it. (erh... or can
I?)Don't open it in with ImageIO.read, but just copy the stream (look at openConnection in the URL API.

Similar Messages

  • Saving an image and data file

    Am am current developing a program similar to the one below using an elvis module.
    I am trying to save am image of the graph but, the save image window keeps popping up because of the loop.
    I just want to be able to click a button and then save the image to a file without the save window popping up every time. 
    Attachments:
    conor.vi ‏57 KB

    Hi cdwyer,
    In your second example's block diagram, you need to have the save button terminal and the associated case structure within your main loop, otherwise the button/case structure is only read/executed the one time.
    An additional tip: When saving "computer graphics", like LabVIEW panels or diagrams, it's nearly always better to save them using the PNG format. PNG format is both compressed (small file sizes) and yet also "lossless compression" (no image degradation) - also it's usually preferable to use true colour (24 bit colour depth).
    JPEG file type is a "lossy" type of compression that is designed for photographics - it will cause blurring and colour distortions when used with computer graphics.
    Mark.
    P.S. Worth a few star ratings?
    Message Edited by Mark H on 02-02-2006 12:11 PM
    Attachments:
    example2 modified.vi ‏72 KB

  • Saving cropped image to a file

    Hello,
    I have a big image, I've cropped it into small slices and saved them in a 2-Dimensional array as an "Image" object.
    Now I am trying to save each "Image" Object to an individual file.
    Now it's really weird because I can save the very first image element in array as a file, but the rest of the elements are BLACK!
    Below is the part of my code.
    ===========================================================
    for( int i=0; i < slicedImageArray.length; i++ )
    for( int j=0; j < slicedImageArray.length; j++)
    BufferedImage bi =
    new BufferedImage( slicedImageArray[i][j].getWidth(),
    slicedImageArray[i][j].getHeight(),
    BufferedImage.TYPE_INT_RGB );
    bi.getGraphics().drawImage( slicedImageArray[i][j].getSlice(),
    slicedImageArray[i][j].getXCoordinate(),
    slicedImageArray[i][j].getYCoordinate(), null);
    File sliceImage = new File("image" + i + j + ".jpg");
    try
    ImageIO.write(bi, "jpg", sliceImage);
    catch(Exception e)
    ====================================================================
    getSlice() method returns "Image object"
    PLEASE HELP!

    it is most likely because you are drawing the image off the range of the buffer:
    bi.getGraphics().drawImage( slicedImageArray[j].getSlice(),
    slicedImageArray[j].getXCoordinate(),
    slicedImageArray[j].getYCoordinate(), null);
    should be:
    bi.getGraphics().drawImage( slicedImageArray[j].getSlice(),
    0,
    0, null);

  • Saving screen image to a file? CP7

    Hi,
    In CP7, is there a way to save a screen shot to a file? I have a client who's users may not know how to capture a screen shot on their computer. We'd like them to be able to click a button on the slide and have an image of that slide (say certificate) be saved to a file on their pc.  Is this possible? How?
    Thanks!
      Lori

    This is not currently possible with standard Captivate functionality.  It might be possible with a widget, but I've not heard of one out there that does this.

  • Saving an Image to a file as jpeg or png

    I am creating a paint program and would like to save whatever user has drawn to a file.
    I can use BufferedImage but when i try to use buffered image then the display of the painting area is set to black and the painting colour is set to white even when i try to change it. How can i avoid this problem while still saving it. By the way the painting area is a custom subclass of JPanel.

    Just look down the page a bit!
    http://forum.java.sun.com/thread.jspa?threadID=606095&tstart=0

  • Help! Saving an image to stream and recreating it on client over network

    Hi,
    I have an application that uses JDK 1.1.8. I am trying to capture the UI screens of this application over network to a client (another Java app running on a PC). The client uses JDK 1.3.0. As AWT image is not serializable, I got code that converts UI screens to int[] and persist to client socket as objectoutputstream.writeObject and read the data on client side using ObjectInputStream.readObject() api. Then I am converting the int[] to an Image. Then saving the image as JPEG file using JPEG encoder codec of JDK 1.3.0.
    I found the image in black and white even though the UI screens are in color. I have the code below. I am sure JPEG encoder part is not doing that. I am missing something when recreating an image. Could be colormodel or the way I create an image on the client side. I am testing this code on a Win XP box with both server and client running on the same machine. In real scenario, the UI runs on an embedded system with pSOS with pretty limited flash space. I am giving below my code.
    I appreciate any help or pointers.
    Thanks
    Puri
         public static String getImageDataHeader(Image img, String sImageName)
             final String HEADER = "{0} {1}x{2} {3}";
             String params[] = {sImageName,
                                String.valueOf(img.getWidth(null)),
                                String.valueOf(img.getHeight(null)),
                                System.getProperty("os.name")
             return MessageFormat.format(HEADER, params);
         public static int[] convertImageToIntArray(Image img)
             if (img == null)
                 return null;
            int imgResult[] = null;
            try
                int nImgWidth = img.getWidth(null);
                int nImgHeight = img.getHeight(null);
                if (nImgWidth < 0 || nImgHeight < 0)
                    Trace.traceError("Image is not ready");
                    return null;
                Trace.traceInfo("Image size: " + nImgWidth + "x" + nImgHeight);
                imgResult = new int[nImgWidth*nImgHeight];
                PixelGrabber grabber = new PixelGrabber(img, 0, 0, nImgWidth, nImgHeight, imgResult, 0, nImgWidth);
                grabber.grabPixels();
                ColorModel model = grabber.getColorModel();
                if (null != model)
                    Trace.traceInfo("Color model is " + model);
                    int nRMask, nGMask, nBMask, nAMask;
                    nRMask = model.getRed(0xFFFFFFFF);
                    nGMask = model.getRed(0xFFFFFFFF);
                    nBMask = model.getRed(0xFFFFFFFF);
                    nAMask = model.getRed(0xFFFFFFFF);
                    Trace.traceInfo("The Red mask: " + Integer.toHexString(nRMask) + ", Green mask: " +
                                    Integer.toHexString(nGMask) + ", Blue mask: " +
                                    Integer.toHexString(nBMask) + ", Alpha mask: " +
                                    Integer.toHexString(nAMask));
                if ((grabber.getStatus() & ImageObserver.ABORT) != 0)
                    Trace.traceError("Unable to grab pixels from the image");
                    imgResult = null;
            catch(Throwable error)
                error.printStackTrace();
            return imgResult;
         public static Image convertIntArrayToImage(Component comp, int imgData[], int nWidth, int nHeight)
             if (imgData == null || imgData.length <= 0 || nWidth <= 0 || nHeight <= 0)
                 return null;
            //ColorModel cm = new DirectColorModel(32, 0xFF0000, 0xFF00, 0xFF, 0xFF000000);
            ColorModel cm = ColorModel.getRGBdefault();
            MemoryImageSource imgSource = new MemoryImageSource(nWidth, nHeight, cm, imgData, 0, nWidth);
            //MemoryImageSource imgSource = new MemoryImageSource(nWidth, nHeight, imgData, 0, nWidth);
            Image imgDummy = Toolkit.getDefaultToolkit().createImage(imgSource);
            Image imgResult = comp.createImage(nWidth, nHeight);
            Graphics gc = imgResult.getGraphics();
            if (null != gc)
                gc.drawImage(imgDummy, 0, 0, nWidth, nHeight, null);       
                gc.dispose();
                gc = null;       
             return imgResult;
         public static boolean saveImageToStream(OutputStream out, Image img, String sImageName)
             boolean bResult = true;
             try
                 ObjectOutputStream objOut = new ObjectOutputStream(out);
                int imageData[] = convertImageToIntArray(img);
                if (null != imageData)
                    // Now that our image is ready, write it to server
                    String sHeader = getImageDataHeader(img, sImageName);
                    objOut.writeObject(sHeader);
                    objOut.writeObject(imageData);
                    imageData = null;
                 else
                     bResult = false;
                objOut.flush();                
             catch(IOException error)
                 error.printStackTrace();
                 bResult = false;
             return bResult;
         public static Image readImageFromStream(InputStream in, Component comp, StringBuffer sbImageName)
             Image imgResult = null;
             try
                 ObjectInputStream objIn = new ObjectInputStream(in);
                 Object objData;
                 objData = objIn.readObject();
                 String sImageName, sSource;
                 int nWidth, nHeight;
                 if (objData instanceof String)
                     String sData = (String) objData;
                     int nIndex = sData.indexOf(' ');
                     sImageName = sData.substring(0, nIndex);
                     sData = sData.substring(nIndex+1);
                     nIndex = sData.indexOf('x');
                     nWidth = Math.atoi(sData.substring(0, nIndex));
                     sData = sData.substring(nIndex+1);
                     nIndex = sData.indexOf(' ');
                     nHeight = Math.atoi(sData.substring(0, nIndex));
                     sSource = sData.substring(nIndex+1);
                     Trace.traceInfo("Name: " + sImageName + ", Width: " + nWidth + ", Height: " + nHeight + ", Source: " + sSource);
                     objData = objIn.readObject();
                     if (objData instanceof int[])
                         int imgData[] = (int[]) objData;
                         imgResult = convertIntArrayToImage(comp, imgData, nWidth, nHeight);
                         sbImageName.setLength(0);
                         sbImageName.append(sImageName);
            catch(Exception error)
                error.printStackTrace();
             return imgResult;
         }   

    While testing more, I found that the client side is generating color UI screens if I use JDK 1.3 JVM for running the server (i.e the side that generates the img) without changing single line of code. But if I use JDK 1.1.8 JVM for the server, the client side is generating black and white versions (aka gray toned) of UI screens. So I added code to save int array that I got from PixelGrabber to a text file with 8 ints for each line in hex format. Generated these files on server side with JVM 1.1.8 and JVM 1.3. What I found is that the 1.1.8 pixel grabber is setting R,G,B components to same value where as 1.3 version is setting them to different values thus resulting in colored UI screens. I don't know why.

  • How do i disable the open/save image dialog box in firefox? I want to directly save the image file to the drive.

    How do i disable the open/save image dialog box in firefox? I want to directly save the image file to the drive without clicking on save option everytime when saving an image. I'm using firefox ver 35.0.1 for windows 7.

    Click on the Firefox menu. Then click "Options". Go to "Applications" tab. Search for jpg and png file type. You will find they have "Always ask" action attribute. Change it to "Save file".
    Hope it will work fine for you.

  • While using a drop-down menu i.e. File, edit, image, or even when saving as and choosing the file type; the list appears and I am able to highlight what i want but cannot click on anything.

    While using a drop-down menu i.e. File, edit, image, or even when saving as and choosing the file type; the list appears and I am able to highlight what i want but cannot click on anything. This is becoming incredibly frustrating. It happens at random time and a restart of the computer is all that helps, then with out any notice it starts to do this again.  Mac Book Pro i7 2.2 16 GB 1333 Ram, (2) 450GB SSD both internal to machine. At this point I am losing file because I am unable to save in the file type I need. Does anyone out there know how to solve this issue?
    Thanks
    phil

    I haven't been unify photoshop much in the past month, but I did try your suggestion and it seemed to work for a while. Today when i went to save a document the same thing happened: click on file>save at this point I can not click on save even though it is highlighted. Tryed to use command s that brings up the save dialogue box, but when I try to change file type I again cannot select it from the drop down menu.

  • How to see all image types when saving an image without selecting "all files"every time

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [[/questions/951766]]</blockquote>
    Hallo, and thank you for reading this.
    I am a person who saves a lot of images online and renames them in different folders in different names like B - 34 or G - 56. I have been working with firefox 10 for quite some time and it had a pretty handy bug (I guess) where I could save an image and firefox would just save the image in it's original type (JPEG,PNG etc) while "save as type" was empty.
    It also always has shown all the image types in the folder where I save the images (except for GIF) and that helpes me quite a lot by saving me the trouble of selecting "all files" every time I save or going to the folder to rename every image.
    Now this seems to be lacking in the newest firefox versions and my question is if I can set firefox to always show me all the image file types when saving an image, instead of only showing JPEG's when I try to save a JPEG.
    Thank you for your time.

    I suspect this is a Windows problem. I am surmising the FilePicker uses the Operating System or Desktop facilities. Does Windows 7 offer any other file categories like ''images'' ?
    I do not normally use Windows 7, but may the option depend upon the directory being an indexed one, I ask after finding this thread ''Bring File types tab back'' [http://www.windows7taskforce.com/view/819]
    This question is a duplicate of [/questions/951764]
    Normally I would lock the duplicate question, but in this instance I will leave it open as it is unanswered and someone may give a better reply.

  • I created an image in Photoshop and saved it as the PSD file. Now when I try and open it it says it is not compatible with my version. How could this be when I created it in this version?

    I created an image in Photoshop and saved it as the PSD file. Now when I try and open it it says it is not compatible with my version. How could this be when I created it in this version?

    That depends on why it won't open.  Most of the time it means the file is corrupted and unlikely to be recovered. If you saved it right after adding or copying a LOT of layers - then it might just be the layer limit and we can attempt to recover it.

  • File name used by plug-in for saving the image file.

    I have a program that creates a web page that has an object tag with a call to a program and that program delivers a PDF file.  When my users want to save that image the name of the image is a random name.  Is there any way to make the plug-in, Adobe, use the meta tag Title or any other infromation that my program can provide, as image (file)  name to be used for saving the image. (the initial suggested name)?  I really appreciate your help.

    One option is to rename the file after it's been exported using Windows File I/O API.

  • Automation in saving a image file with a specific max file size

    Hi everyone,
    I hope someone can help me by this.
    Background info:
    We got several image files every 2 weeks which should be edited and mainly reduced in size for web purpose. This work needs 1 work day for one man/woman to do, because he/she has to open the file save for web and then set the quality to a value were the file is nearly about 150-200 KB in size.
    The images are different, some have few colors, some have a lot of colors and there are also different in resolution. But they should not be reduced in resolution, only in quality. All other specs of the image should be kept 
    Is there any possible script, plug-in or similar which can do the same (Saving with a specific max. file size) in some automatic and faster way?
    Any help is really appreciated!
    Thanks in advance!
    Kind regards
    Packesel

    *push*
    Hi everyone,
    I still need help with this. Is there any tool (OS X) or script for Photoshop who can fulfill this (see title).
    ANY help is really appreciated!
    Thanks in advance.
    Regards
    Packesel

  • An error occurred saving the images to the chosen file location

    I am trying to save the scans from my HP Officejet 6500.  I receive the following error message:
    An error occurred saving the images to the chosen file location.
    I have Win 7.
    I can scan and save if I choose to use the picture option but I can't use the feeder with the picture option.  It is only good if I have 1 page.

    I received this exact same message:
    an error occurred saving the images to the chosen file location.
    8,[(8,106,0)]
    I have not had the time to verify this, but I suspect the security settings on any other location you specify are not the same as those of the default.  i.e. C:\Users\%Username%\Documents\My Scans
    When I used the default location and base name the software provided, it worked.
    My guess is Microsoft and/or HP may have changed the security permissions for something in the path folders and the Scanning Software is therefore not permitted to write into the location you entered.

  • How to see images in m4a file using itunes

    So I used garageband to make an enhanced podcast. It has audio and images. That went fine, and I saved it as an m4a file (from the share menu, I chose "Export podcast to disk").
    When I open it in itunes, I hear the audio, and can choose the chapters, but I cannot see the pictures (except in the chapter menu). I am using iTunes 10.3.1. How can I get itunes to show the pictures? The pictures show up fine if I view the podcast using Quicktime.
    I don't want to put the podcast up on the itunes store or anything like that. Ultimately, I'd like to embed the podcast into a website for my course. I am a college professor.
    Thank you!

    You can't, iTunes is only used to set the location the photo's are loaded from, they aren't held anywhere in iTunes itself. Since they have to be on the computer anyway to load them onto the iPod you view them from the folder or album they are in or directly from the iPod screen.

  • Saving an image with altered metadata corrupts it

    When I apply a set of metadata by Nikon NX2 and then save the image on iPhoto, then it becomes impossible to open it again: the error I receive is the following (in Italian):
    Impossibile caricare il file: Macintosh        HD/Utenti/fbartolom/Immagini/iPhoto        Library/Masters/2010/03/20/20100320-121339/DSC_6029_5.NEF        Formato colore non valido. Il formato del file non è supportato.
    Please not that if I just save the image on the disk the problem does not surface, neither if later I import it to iPhoto and open it again.
    So there must be a glitch in the direct saving from NX2 to iPhoto. Has anyone some cue on what is the problem and how to solve it? Of course saving each image and importing them again should be a little of an overkill.

    Yes, I am using it since I bough it nearly 3 years ago without any problem. Frankly I am non sure I understood what you said: so I explain what I do and what iPhoto and NX2 do:
    1) I click modify on a NEF image in iPhoto 11.
    1') iPhoto duplicated the photo and launches NX2 on this duplicated photo.
    2a) I edit the picture and Save the image.
    2a') iPhoto 11 correctly opens this latter image - I will have to manually delete the original photo.
    2b) I enter the metadata in the image on NX2 and SAVE.
    2b') iPhoto reports an error when I try to re-open the saved NEF file.

Maybe you are looking for

  • TS1567 5th Gen I-Pod Touch not Syncing, does come up on PC.

    My 5th Gen I-Pod Touch no longer connects to I-Tunes, or Microsoft Sync (In my 2013 Ford Focus) through a sync cable. My computer however, does see the I-pod as a external device, and it does charge through the Sync cable. I have reset the I-Pod full

  • How to get the sequence value from the database

    Hi I created one sequence in the database. Then I want to take the current value or nextvalue of the sequence in a java program. How can i do this? can anybody please explain me? Thank you so much.

  • Opening same URL in another tab or window

    switcher here: in windows I could open a new window and the website that opened by default was the one that was already open (so now I have 2 windows with the same site)...Is there an equivilent Safari? How about Camino or firefox? Right now i have b

  • Extracting Outline from Planning using ODI

    Hi John, I would like to extract the outline from my Planning application using ODI. When i did the extraction from the essbase, most of the properties of the members are differing wrt the Planning properties. Is there any way to extract the outline

  • Qmaster and Compressor - the big questions....

    I have a G5 and a newish G4 laptop. I've looked up and down this discussion, but still have these basic questions: 1. Can both computers work from one source file and create one compressed file, together, without splitting the result into segments? (