0

I tried to convert a bmp:

File file = new File(source.getText());

    try {
        BufferedImage i = ImageIO.read(file);
        if (i != null) {

            BufferedImage convertedImg = new BufferedImage(i.getWidth(), i.getHeight(), BufferedImage.TYPE_4BYTE_ABGR);
            boolean drawImage = convertedImg.getGraphics().drawImage(i, 0, 0, null);

                File f = new File(output.getText().concat(File.separatorChar + "out.bmp"));
                boolean write = ImageIO.write(convertedImg, "BMP", f);
        } else {
            //...
        }
    }catch (Exception e) {
            e.printStackTrace();
    }

But it doesn't write the image correctly. As I open the bmp it says the file is empty?? What am I doing wrong?

Edit: write returns false.

  • 1) For better help sooner, post an [SSCCE](http://sscce.org/). 2) One way to get image(s) for an example is to hot-link to the images seen in [this answer](http://stackoverflow.com/a/19209651/418556). 3) Change code of the form `catch (Exception e) { ..` to `catch (Exception e) { e.printStackTrace(); // very informative! ..` – Andrew Thompson Nov 14 '13 at 11:06
  • i do printStackTrace() but this doesn't throw any Exceptions – user2991708 Nov 14 '13 at 11:36
  • If `write` is `false`, nothing was written. You should not have an empty file in this case, but it could be you are on an old JRE. What version do you run? – Harald K Nov 14 '13 at 13:09
  • *"i do printStackTrace()"* Show me what is changed by adding an SSCCE of the altered code to the question as an [edit](http://stackoverflow.com/posts/19975896/edit). – Andrew Thompson Nov 14 '13 at 14:23

0 Answers0