Saving an Image

Hi i have got a problem i'm writting a program that reads in a image, get the image pixels, alter the pixels and then write the image back out again. the problem is that when i write it back out the image goes from colour to gray scale and also when i save the image out without alter the image the image still changes slightly.
to be more precise i save the image as a buffered image, get the pixels , edit the pixels and then save it back. i know that the editing of the pixels is not the problem becasue, when i run the code without editing the pixels and just save the image as a new image. it is still changed.
try {
fos = new FileOutputStream(newFilename+".JPG");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
try {
ImageIO.write(newImage,"JPG",fos);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}above is the code that i use to save an image.
so if anybody can help me and point me in the right direction that would be great.

well i found out that i was altering the pixels somewhere else which is why i had the problem.
but now that i have fixed that and i want to alter only one pixel then all the pixels arround the one i want to alter will chage to a different colour.
i know this becasue i have created a 5*5 image with all pixels being red then i try to alter the 5th across and 4th down. but the result is that from that point the pixels will also change.
i have tried this saving the image as a JPEG, GIF and as PNG and i get the same result

Similar Messages

  • 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 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.

  • When saving an image in PS CS 6, and going back to Lightroom 5. The original image and the edited image are at the end of the line up.

    I'm using a Mac, Lightroom 5 and Photoshop CS 6. I've started having an issue with the line up in Lightroom 5 after saving an image from PS CS 6. For some reason when I save the edited image form CS 6 it's taking the edited image and the original image and putting it at the end of the line up in Lightroom. If I take the edited image and move it to the right of the original it will put both of them back in the line up where they should be. How do I fix this. I've been looking in the menu for some kind of setting  with no luck.

    Change the sort order. View->Sort

  • Trouble saving the image, save as button not working

    i'm having trouble in saving the image in PNG format, it seems that the "save as" button is not working properly, what should i do?

    Save from what program? On what system? In any case, ask in the product forum of whatever program you are referring to...
    Mylenium

  • 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.

  • Saved an image as library and now all in iphoto images disappeared

    I was saving an image from email to iphoto, and somehow it was saved as my iphoto library. All of my photos are now gone, there were hundreds, and the one image I just saved is just there. Where are my photos??? Don't they get saved somewhere on my hard drive aside from being hosted iphoto. I have a MAC AIr and iPhoto '11.

    Rename it back.
    (110127)

  • Saving an image in Root folder of tomcat

    Hello,
    i have an urgent problem with saving an image in the root folder of tomcat, which I want to do without having to specify the entire path.
    I have created a class, which i use as a bean in a jsp to save an image to the tomcat root folder.
    If I use the following command, the image is saved:
    ChartUtilities.saveChartAsJPEG(new File(
    "C:/Program Files/Apache Software Foundation/Tomcat 5.5/webapps/trader/images/charts/1.jpg"), chart, 550, 260);
    However, I should be doing it like this, which doesn't work and throws me an IO exception:
    ChartUtilities.saveChartAsJPEG(new File("images/charts/1.jpg"), chart, 550, 260);
    Cheers

    Didn't we have this discussion in another thread? You can't give something urgently. It's semantically anaphoricular.

  • 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.

  • I am using adobe photoshop cs6. I am facing a problem. When i save any image as "save for web". After saving image it show cropped. An image show many parts of the image after saving the image. Please help me. Thanks in advance.

    I am using adobe photoshop cs6. I am facing a problem. When i save any image as "save for web". After saving image it show cropped. An image show many parts of the image after saving the image. Please help me. Thanks in advance.

    Just go back in photoshop and use the Slice Select tool, then just click and select the slice and hit delete - if you're not sure which one is the active slice just right click and find the one that has the Delete Slice option.
    It's possible you either added the slices by accident or if you received it from someone they just had the slices hidden. For the future, you can go to View > Show > Slices to display (or hide) slices.

  • I am using a MacPro running OS 10.6.8. When saving an image in PS CC I no longer have a thumbnail of the image in my folder , just a generic PS symbol thumbprint. What do I do to get my image thumbnail back?

    I am using a MacPro running OS 10.6.8. When saving an image in PS CC I no longer have a thumbnail of the image in my folder , just a generic PS symbol thumbprint. What do I do to get my image thumbnail back?
    Adobe Creative Cloud

    Photoshop CC needs at least OSX 10.7-10.9
    You may be able to install and run it on 10.6.8, but as I understand it the rules for generating thumbnails has changed with Apple and CC writes them to suit the required OSX.
    Photoshop CS6 will always give you image thumbnails but CC and CC 2014 have had thumbnails generated differently for the required OSX.
    You will have to upgrade to 10.7,10.8, or 10.9
    My file saving preferences are set like this:

  • When I have resized and saved an image in Photoshop (CS, version 8.0 for Mac) using image size, why is it so large when I open it in preview or another image viewer? Has it actually saved according to the size I specified?

    When I have resized and saved an image in Photoshop (CS, version 8.0 for Mac) using image size, why is it so large when I open it in preview or another image viewer? Has it actually saved according to the size I specified?

    You want to view the image at the Print Size, which represents the size that shows in the Image>Resize Dialog.
    View>Print Size
    Since screen resolution is almost always lower that the print resolution (somewhere between 72 and 96 usually), images will always look bigger on the screen, unless you view them at print size.
    (apple Retina displays have a much higher resolution than normal screens, closer to the average print size resolution)
    more info:
    Photoshop Help | Image size and resolution

  • Saving & populating images in apex

    hi
    I want to save & retrieve employee photoes in database using apex. can anyone help me.
    vijay

    Hi Vijay,
    Inside your workspace do you have sample application-> Run it->Go to Tab-> product-> Click Create Product-> Form shows input field with browse button-> Edit page to see the code to implement saving & populating images in apex.
    This is table based storage inside apex.
    If you want to store inside apex for your designing then go to shared component -> image-> create new image uploading-> Access from your page will be like the below.
    <img src=#APP_IMAGES#temp.jpg>
    This link also help.
    http://download.oracle.com/docs/cd/B31036_01/doc/appdev.22/b28839/up_dn_files.htm
    Thanks,
    Loga
    Edited by: Logaa on Sep 15, 2010 12:14 AM

  • Saving Attached Images in Aperture

    With iPhoto, when saving an image attached to Email, I use the <save> button, and iPhoto is on the list.
    How is this done with Aperture? How are attached images easily saved?
    Thanks.

    There isn't a way but you could make a Service to do the job with Automator
    Regards
    TD

  • 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

  • How do u work the alarm clock on a mini?

    hi i left my fone at work one day and i use the fone as my alarm clock, because i had no alarm due to fone being at work i wanted to use my ipod alarm,i tried setting it but it didnt go off, how do i get it to work, do u have to plug it in ur comp, o

  • Redirect external user (internet) & internal user (intranet)

    Hi, we are developing a public portal services in which we have two kind of user: a) public user that access through internet to the portal. b) internal user that access inside a domain to the portal. We want to know How we can know which is the exte

  • The submit button

    I'm having issues with the submit button. I'm using Acrobat X to design a fillable form, all was working well. When the submit button is clicked a window pops up asking if i'd like to use my desktop email application or i'd like to save the form to u

  • How do you open old TIFF files in Photoshop CC

    An external hard disc crashed and was recovered. I have quite a lot of old TIFF files on it which I cannot open. I get an error message stating 'the TIFF file uses an unsupported compression method'. I have only used Adobe since Adobe 4.0.

  • Numeric Stepper to display text

    I am trying to use Flex for a small section on a page that pops up.  The option will have many fields that normally would be in a combo box but because of the height of the location I dont have room to display all the content.  I was wondering if I c