Problem saving an image to disk - sometimes its black??

Hi i'm trying to create a thumbnail of an image and save it to disk using Image and Graphics2D. The problem i'm having is that sometimes when i save the image its blank\black, it seems totally random in doing this i.e. it will work find one time and then not work the next time (i'm actually processing a whole folder of images in my program)
Image image = new ImageIcon(imgfile).getImage();
BufferedImage bi = new BufferedImage(100,100,BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = bi.createGraphics();
if(image.getWidth(null) > image.getHeight(null)){
// create landscape image thumbnail     
image = image.getScaledInstance(133,100,Image.SCALE_DEFAULT);
// here i'm cropping the image so that its square + focusing the center of the image
g2d.drawImage(image,                               0,                              0,                              100,                              100,                              15, // start x coordinate                         0, // start y corodinate                         115,// end x corodinate                         100,// end y coordinate                         null);                              
else...
If anyone could shed any light on to why this problem is occuring i would be really greatful, its driving me nuts! :P
btw: if anyone knows of a better way of doing this please let me know to. i'm sure u should b able to scale the image and crop it just using Graphics2D, just dont know how though...
Many Thanks,
Tom

some of the images that i'm processing are dark but there are many others that aren't, all images that are outputed are totally black.
I'm kind of suspecting that it may be a case of the image isn't being fully loaded when the scale\crop is performed. i have noticed that the larger the file\resolution the more likely it will be draw\saved correctly.,this leads me to beleave that the problem may lie in the loading...
I have been looking at MediaTracker as that seems to be meant for this sort of situation but all the examples i see involve JFrames\Applets which my program doesn't make use of. Am i right in thinking that MediaTracker requires a java.awt.Component when being created? is there anyway round of this or is there anything else you can think of that i could use to do a similar job?
Many Thanks, Tom

Similar Messages

  • I am having problems saving certain images

    I am having problems saving certain images. For example, on Ebay while viewing an auction item, when you click on the image to view the larger picture it opens in a new window. With Internet Explorer, you can "right-click" and "save picture as". With Firefox 3.6.9 the "save picture as" option is not availabale. Other options such as save "save page as" are available, but not "save as," or "save picture as." Any ideas? Thanks

    I have found a solution to the problem. Apparently there is an addon to fix this. Had no idea a specific google search for "trouble saving images on ebay" would turn up anything.
    https://addons.mozilla.org/en-US/firefox/addon/13802/

  • Problem while writing image to disk..............

    AOA
    in my application i scan an image and then try to write it to c:\image folder in windows then it gives following exception.
    java.io.FileNotFoundexception: c:\image (Access is denied)
    i have checked the security and permissions for C.
    they allow the user to write but problem is still there.
    what may b the reason

    If I use the following code:
    try {
        FileWriter out = new FileWriter("C:/DRIVERS");
    } catch(IOException ioe) {
        ioe.printStackTrace();
    I get
    java.io.FileNotFoundException: C:\DRIVERS (Access is denied)======================================================
    The above is have relative path in
    FileWriter out = new FileWriter("C:/DRIVERS");instated of giving relative("C:/DRIVERS") path you just give the absolute
    path.
    FileWriter out = new FileWriter("C:/DRIVERS/filename/yourscanimage");

  • Problem saving html images

    I'm trying to make a simple web page in PS, and when I export for web & devices whatever I do the file saves as 4kb on the desktop.
    If I open it it displays correctly, but then when try to upload it with an FTP client the file shows up as 0kb. I have followed the Adobe video tutorial and don't know where I'm going wrong. Has anybody any tips?

    It seems obvious that you are faltering in the upload for some reason.
    What are you using to upload?
    It's also important to note that there is no such thing as "an html image". HTML is a scripting language, it's code. Images are images. Web pages can contain both or only one. Most webpages are a mixture of HTML with linked images inside the code.
    Perhaps you aren't uploading both the code and the images.

  • Colour problems saving Ilustrator file to pdf and jpeg (blacks go brown + some quality is lost)

    Hi,
    I was wandering id anybody could help me with a problem that has plagued me for a few projects now. I can't seem to find a solution.
    When I have a file in Illustrator that I want to save as or export as a PDF or JPEG whenever I save it the colours shift and the quality drops.
    Most noticiably black boxes goes to a muddy brown when saved to JPEGS, but I have also noticed tones in Photographs change quite a lot when saving as PDF.
    I have tried to tweek every type of setting there is. higher resoulution, compression, sampling, down sampling, PDF preset, print quality etc.but nothing seems to sort it out. PDF's arent as much as a problem as the JPEG but the only way I have managed to get a PDF up to a reasonable standard is by wacking everything up so there is no compression or downsampling which makes ginat files I cant email....
    Im sure the problem probably lies within the combination of each of these together but I cant seem to find out what that is.
    Has anybody else had this problem or know how to fix it? I have been searching blogs for so long?
    Thanks
    Leo
    (Before saving to JPEG)
    (After)
    Notice the black box with text in has turned a bit brown
    Also brown in the seat base has gone more orange and the whole picture has generaly lost quality.

    Leo,
    The file is CMYK Color Mode. Do you export to a CMYK JPEG or an RGB one?
    It is conceivable that the colour conversion of photographs (which are originally RGB) may cause the PDF issue.
    Obviously, you will have to choose a Color Mode. If (also) intended for print, the obvious choice is CMYK, but that often affects the appearance or artwork/images originally created in RGB.
    Colour management/settings and calibration may also be significant.

  • Problem Saving Gererating GIF Image

    Hello, we are having a problem in production environment when try to right mouse and select Print on an mii grid. Works just fine in all of our non-production environments. Checked the System Security pull downs and they all matched non-prod. Was not sure which one to compare, was not a ImageStorageServlet on pull down menu.
    After right mouse and select Print on grid, get:
    -Java Applet Window popup message - Problem Saving Gererating GIF Image
    -Then - blank browser page - .../XMII/ImageStorageServlet/View/null
    - Non-production servers works fine produces grid on browser page - XMII/ImageStorageServlet/View/2084280301
    NetWeaver Log:
    Location - com.sap.xmii.servlet.ImageStorageServlet
    Full Message Text
    ImageStorage - Error saving GIF file 
    Full Message Text
    ImageStorage - Error generating GIF output
    Any help would be appreciated.
    Thanks

    David,
    Have you put in a support ticket for this? I recommend doing so since its occurring in your production environment. You should also attach your log files as well.
    Regards,
    Kevin

  • Problem in saving the image into SQL database..

    Hello,
    In my application I have to save image file (say jpg) into the database and retrieve back and display it on the applet. I am through with grabbing the pixels of the image & sending the pixel array to the servlet but I am struck in how to store the image into the database and retrieve the same.
    Can anybody please help me in this regard... its really urgent...
    Thanks in advance
    Swarna

    Hello.
    I've been researching this problem (saving images in a MySQL database) in order to accomplish a task I was assigned to. Finally I was able to do it. I'd be glad if it will be of any use.
    First of all: the original question was related to an applet. So, the post from rkippen should be read. It says almost everything, leaving the code job for us. Since I managed to write some code, I'll put it here, but I'm not dealing with the byte transferring issue.
    To obtain a byte array from a file I'd open the file with FileInputStream and use a loop to read bytes from it and save them into a ByteArrayOutputStream object. The ByteArrayOutputStream class has a method named �toByteArray()� which returns an array of bytes (byte [] b = baos.toByteArray()) that can be transferred in a socket connection, as said by rkippen.
    My problem was to save an image captured by a web camera. I had an Image object, which I converted into a byte array and saved into the database. Eventually I had to read the image and show it to the user.
    The table in the MySQL database could be:
    CREATE TABLE  test (
      id int(11) NOT NULL auto_increment,
      img blob NOT NULL,
      PRIMARY KEY  (id)
    )I had problems trying to use the �setBlob� and �getBlob� methods in the Statement object, so I used the �setBytes� and �getBytes� methods . In the end, I liked these methods most because they where more suitable to my application.
    The database operations are:
        public int insertImage(Image image) throws SQLException {
            int id = -1;
            String sql = "insert into test (img) values (?)\n";
            PreparedStatement ps = this.getStatement(sql);  // this method is trivial
            byte [] bytes = this.getBytes(imagem); // * see below
            ps.setBytes(1, bytes);
            ps.executeUpdate();
            id = ps.getGeneratedKeys().getInt(0); //Actually I couldn't make this line work yet.
            return id;
        public Image selectImage(int id) throws SQLException {
            Image img = null;
            String sql = "select img from test where id = ?\n";
            PreparedStatement ps = getStatement(sql);
            ps.setInt(1, id);
            ResultSet rs = ps.executeQuery();
            if (rs.next()) {
                byte [] bytes = rs.getBytes(1);
                img = this.getImage(bytes); // * see below
            return img;
        }* If the bytes are read directly from a file, I think it is not necessary to convert it into an Image. Just send the bytes to the database method would work. On the other hand, if the image read form the DB will be written directly into files, the bytes obtained from rs.getBytes(1) would be enough.
    The image operations are:
        public byte [] getBytes(Image image) {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            try {
                ImageIO.write(this.getBufferedImage(image), "JPEG", baos);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return baos.toByteArray();
        public Image getImage(byte [] bytes)  {
            Image image = null;
            ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
            try {
                image = ImageIO.read(bais);
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            return image;
        public BufferedImage getBufferedImage(Image image) {
            int width = image.getWidth(null);
            int height = image.getHeight(null);
            BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = bi.createGraphics();
            g2d.drawImage(image, 0, 0, null);
            return bi;
        }That's it. I hope it is useful.

  • My time machine does not want to save any more the data from my powerbook 13" Snow Leopard; i get the message "Time Machine could not suppress the disk image of saving "Volumes/Time Capsule Disk/PowerBook _2011_03_21_123627 sparsebundle" What should I do?

    My time machine does not want to save any more the data from my powerbook 13" Snow Leopard; i get the message "Time Machine could not suppress the disk image of saving "Volumes/Time Capsule Disk/PowerBook _2011_03_21_123627 sparsebundle" What is the problem? What should I do?
    Thanks !!
    Alain

    Could that read " . . . could not access . . ."?  If so, try repairing your backups, per #A5 in Time Machine - Troubleshooting.
    If not, or if that doesn't help, see #A1 there. Use the TM Buddy widget it details to copy and post the messages here.

  • Display image in JPanel without saving any file to disk

    Hi,
    I am fetching images from database. I am saving this image, display in JPanel and delete it. But this is not actually I want.
    I wish to fetch this image as stream , store in memory and display in JPanel without saving any fiel in disk.
    I wonder if it is Possible or any used implementation that I can use in my project. Any idea or experienced knowledge is enough.
    Thanks

    In what format is the image coming to you from the database? If it's an InputStream subclass, just use javax.imageio.ImageIO:
    InputStream in = getImageInputStream();
    BufferedImage image = null;
    try {
       image = ImageIO.read(in);
    } finally {
       in.close();
    // ... Display image in your JPanel as you have beenIf you receive the image as an array of bytes, use the same method as above, but with a ByteArrayInputStream:
    byte[] imageData = getImageData();
    ByteArrayInputStream in = new ByteArrayInputStream(imageData);
    BufferedImage image = null;
    try {
       image = ImageIO.read(in);
    } finally {
       in.close();
    // ... Display image in your JPanel as you have been

  • I have problems with uploading images to my printing company have the images have been manipulated through CS6 i have saved images as jpeg but the printer company tell me they are not j peg, they will not upload images save from a camera are fine

    I have problems with uploading images to my internet printing company when  the images have been manipulated through CS6 and  i have saved images as jpeg  the printer company tell me they are not j peg,
    but images saved from my phone or camera images that have not been manipulated upload fine, What am i doing wrong?

    Save/Export them as JPG. Photoshop defaults to PSD, so make sure you select JPG and not just rename the file to .jpg.
    There are two ways to save them as JPG: Regular Save as option or Save for Web & Devices
    Take your pick.

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

  • My iPhone 4 home button doesn't always work. sometimes its just not responsive. other times, it works great. what's the problem, and how do I get it fixed? my iphone  is 2 days old

    my iPhone 4 home button doesn't always work. sometimes its just not responsive. other times, it works great. what's the problem, and how do I get it fixed? my iphone is 2 days old

    Hi there,
    I would recommend taking a look at the troubleshooting steps found in the article below.
    iPhone: Hardware troubleshooting
    http://support.apple.com/kb/TS2802
    -Griff W.

  • Saving an imaq image to disk using CWIMAQVisi​on

    OK, I've given up on trying to get my code to work, so I'm going to try and adapt the 'Low-Level Grab' VB example to my uses. 
    I want to acquire an save an image every 10 min or so.  I know how to config the timer for this, but when it comes to saving the image...
    When I use the line of code
    errorCode = CWIMAQVision1.WritePNGFile(myImage, "C:\image.png")
    I get:
    'Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateEx​ception' was thrown.'
    Where and how do I need to define and configure the CWIMAQVision Object to correctly save an image and eliminate this error?

    Warning    1    The referenced component 'niimaq1394' could not be found.    
    Error   
    2    'AxCWIMAQViewer' is ambiguous in the namespace
    'NationalInstruments.CWIMAQControls'.    F:\Documents and Settings\All
    Users\Documents\National Instruments\NI-IMAQ for
    IEEE-1394\Examples\MSVB.NET\Low Level Grab1394.NET\Low Level
    Grab1394.vb    46    40    Low Level Grab1394
    Error    3   
    'AxCWIMAQViewer' is ambiguous in the namespace
    'NationalInstruments.CWIMAQControls'.    F:\Documents and Settings\All
    Users\Documents\National Instruments\NI-IMAQ for
    IEEE-1394\Examples\MSVB.NET\Low Level Grab1394.NET\Low Level
    Grab1394.vb    63    32    Low Level Grab1394
    Error    4   
    'CWIMAQImage' is ambiguous in the namespace
    'NationalInstruments.CWIMAQControls'.    F:\Documents and Settings\All
    Users\Documents\National Instruments\NI-IMAQ for
    IEEE-1394\Examples\MSVB.NET\Low Level Grab1394.NET\Low Level
    Grab1394.vb    236    24    Low Level Grab1394
    Error    5   
    'AxCWIMAQVision' is ambiguous in the namespace
    'NationalInstruments.CWIMAQControls'.    F:\Documents and Settings\All
    Users\Documents\National Instruments\NI-IMAQ for
    IEEE-1394\Examples\MSVB.NET\Low Level Grab1394.NET\Low Level
    Grab1394.vb    240    34    Low Level Grab1394
    If I
    'Add Reference', browse to my WINDOWS/System32 folder, I don't see the
    niimaq1394.dll file.  I DO see: niimaqci.dll, niimaqdx.dll, and
    niimaqmem.dll
    Should I add any of those?  I was previously
    running an earlier version of theNI-IMAQ software and this is when I
    was successfully able to add the niimaq1394 as a reference.

  • Issues with saving disc images using Toast 8

    I am having issues saving disc images to my portable hard drive using Toast 8.
    First, I'm attempting to save Dual Layer disc images to my portable hard drive for future use. I turn compression off and select DL DVD above the burn button, and select "save as disc image" from the file menu. As that point the program seem to freeze and I get the whirly-spinning rainbow. After a few minutes a window asks me if I'm buring single or dual layer. I select dual layer. Then a box appears that says "writing ...".
    After it's complete I check the portable hard drive and I've got EIGHT disc images all titled "SAMPLE DISC IMAGE TITLE.TOAST.001" .....002, 003, 004, 005, 006, 007, 008. File numbers 002-008 open in itunes, and file number 1 mounts with an error that will cause Toast to crash.
    This is so weird and confusing.
    When I save the image to the desktop, its saves fine. BUT, when I try to copy it to the portable hard drive it gets all the way to the end and reports an error message.
    Please help. Thanks
    17 inch PowerBook G4 1.67Mhz 80 GB   Mac OS X (10.4.9)   External HD: Lacie Portable 100gb

    After several weeks of searching and an error code 1309 I discovered the issue is not with TOAST but with my external hard drive. The drive format is FAT32 which does not allow single files to be transfered in excess of 4gb. I was attempting to create disc images of dual layered dvd's which can be up to 8 gb. Since the drive was incapable of accepting a file that size it created seperate files that made up the size of the original file.
    Example: 7.8gb file transfered to FAT32 external LACIE drive. Lacie creates 8 files: 7 are 1gb, 1 is .8gb.
    There is probably a program that could put these files back together but I've already experienced too great of an ordeal.
    Unless the user needs the external drive for use on a PC & MAC there is not a reason to have the format of the drive set to FAT32.
    I will be using Disk Utility to reformat the drive to "HFS+" in hopes to solve this problem.
    17 inch PowerBook G4 1.67Mhz 80 GB   Mac OS X (10.4.9)  

  • How to store images as disk files rather than in iphoto db

    Is there a way to make iPhoto maintain the images as disk files, rather than import them into iphotos massive database file. I would prefer to use iphoto to just store a link to the photo, rather than the photo itself. That way I can work with the image in photoshop or whatnot without having to jerk around with the iPhoto database/

    Welcome to the Apple Discussions. No need to find a workaround. You can use Photoshop from inside iPhoto.
    Using Photoshop (or Photoshop Elements) as Your Editor of Choice in iPhoto.
    1 - select Photoshop as your editor of choice in iPhoto's General Preference Section's under the "Edit photo:" menu.
    2 - double click on the thumbnail in iPhoto to open it in Photoshop. When you're finished editing click on the Save button. If you immediately get the JPEG Options window make your selection (Baseline standard seems to be the most compatible jpeg format) and click on the OK button. Your done.
    3 - however, if you get the navigation window that indicates that PS wants to save it as a PS formatted file. You'll need to either select JPEG from the menu and save (top image) or click on the desktop in the Navigation window (bottom image) and save it to the desktop for importing as a new photo.
    This method will let iPhoto know that the photo has been editied and will update the thumbnail file to reflect the edit..
    NOTE: With Photoshop Elements 6 the Saving File preferences should be configured: "On First Save: Save Over Current File". Also I suggest the Maximize PSD File Compatabilty be set to Always.
    If you want to use both iPhoto's editing mode and PS without having to go back and forth to the Preference pane, once you've selected PS as your editor of choice, reset the Preferences back to "Open in main window". That will let you either edit in iPhoto (double click on the thumbnail) or in PS (Control-click on the thumbnail and seledt "Edit in external editor" in the Contextual menu). This way you get the best of both worlds
    2 - double click on the thumbnail in iPhoto to open it in Photoshop. When you're finished editing click on the Save button. If you immediately get the JPEG Options window make your selection (Baseline standard seems to be the most compatible jpeg format) and click on the OK button. Your done.
    3 - however, if you get the navigation window that indicates that PS wants to save it as a PS formatted file. You'll need to either select JPEG from the menu and save (top image) or click on the desktop in the Navigation window (bottom image) and save it to the desktop for importing as a new photo.
    This method will let iPhoto know that the photo has been editied and will update the thumbnail file to reflect the edit..
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto (iPhoto.Library for iPhoto 5 and earlier) database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger or later), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 6 and 7 libraries and Tiger and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.≤br>
    Note: There now an Automator backup application for iPhoto 5 that will work with Tiger or Leopard.

Maybe you are looking for