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);

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

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

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

  • PSE10- Possible to multi-crop images from scanner?

    I'm taking the task of digitizing hundreds of old photos.  Currently, using my flatbed scanner, I scan 4 pics at a time.  Then I use PSE10 Editor's tool of "Divide Scanned Photo" to split the pictures into 4 different files.  However, sometimes this tools doesn't recognize all 4 pics correctly and I have to crop manually.  This can be tedious to crop, save, open the old file again, crop, save....and do this 4 times.  Is there a way to select multiple crop images from a file and export each to a new file? 
    Any advice is appreciated on my tedious task. 

    Thanks Barbara.  I have a really old flatbed HP scanner and am using regular Windows fax & scan to capture the images.  It's my understanding that newer HP scanners come with this type of software.  Didn't really want to invest in a new scanner.  I've tried a few trials of scanning software, but found PSE10 actually does a better job than them in it's dividing scanner pics.  I'll just deal with the ones that it can't handle manually.  Maybe we'll see a feature where we can crop and export multiple parts of a file in a future release. 

  • I have a problem when cropping 8 but tiff files in elements 12. Once area is selected and I crop the image it disappears. The file no. sill shows but the image is not viewable. I have saved the file from that point and tries reopening but the image isn't

    Has anyone experienced this before ? I have previously been able to crop images with no problem. Recently when I open an image and crop it and confirm the action the image 'disappears' If I save and go to reopen the file is there but it will be  zero meg in size.

    Hi,
    Try resetting the crop tool.
    To the right of the tool option bar, click on the little horizontal lines and you should see reset tool option.
    Good luck
    Brian

  • How to retrieve original RAW image after cropping and opening RAW file?

    Hi
    I have a Canon EOS 350D camera and now have PSE 9.  I have taken some RAW images & imported them into PSE 9 OK.  I know the original RAW image is retained after editing.  However, after cropping a RAW image in the Editor and then "Opening" and "Saving as" a PSD or JPEG, I then close the image in Editor and the cropped image appears in the Organiser.  That is as it should be, I think.  If I then wish to start again from scratch on the original RAW image, it seems to me that I have to manually delete the edited version and the .xmp file in Windows Explorer, and then double click the original RAW file in Windows Explorer, which then opens correctly in PSE 9 Editor.  Can this be done from PSE 9?

    When you open the original camera raw image, go to the flyout menu
    and choose Camera Raw Defaults, that resets everything but the crop, straighten,
    and rotatate settings.
    To get rid of the crop and/or straighten settings, click and hold on the crop tool and choose Clear Crop.
    To reset the Image rotation settings, you have manually rotate back using the image rotate buttons.
    MTSTUNER

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

Maybe you are looking for

  • Cannot see mobile.me in settings on my iPod touch.

    Is this an application that must be installed.

  • Problem with Capturing a Table

    When I have a function that refers to a table outside of the sheet that I am working on, and I try to capture that table so I can use it over again on another sheet, it does not save any functions that reference the other table outside of the one tha

  • Need help with XML delay   URGENT!!!

    Hi i need help making a flash movie to load everything from xml. It has to load text, images and flv, but, it has to load them and end them at the time said in the xml. So flash loads and unloade the text or image or video at the time specified in th

  • Scaling mobile app works fine on the X but not on the Y

    I originally made my app to work for iphone only but I am now scaling it to work on Ipad/ Android etc. I am doing all the scaling manually. It is a tabbed application. I am scaling all x and y locations and widths and heights by a scale factor that i

  • Dynamic paragraph for Sapscript

    Hi all, I need to write a sapscript that require to get the paragraph from abap program. Is this possible for sapscript? Normally, we only choose the desire paragraph format on the left hand side on SE71. Can sapscript get the paragraph format via ab