readthefuckingmanual.net

[SOLVED] javax.imageio.IIOException: Invalid argument to native writeImage

Error added: 2013-01-06T17:33:05Z

0 people waiting for the answer...

1 answers found.

Answer 2439 (100.0% helpful)

        try (InputStream inputStream = new ByteArrayInputStream(data)) {

            BufferedImage originalImage = ImageIO.read(inputStream);
            int w = originalImage.getWidth();
            int h = originalImage.getHeight();

            BufferedImage newImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
            int[] rgb = originalImage.getRGB(0, 0, w, h, null, 0, w);
            newImage.setRGB(0, 0, w, h, rgb, 0, w);

            return newImage;
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
Permalink

Add an answer/solution

If you know the answer, please add your own solution below.
If you don't know, but find out later, please come back and share your answer - there will be other people struggling with this too.


Please enter 61948 here

If you want to be notified via email when this is solved, enter your email address here: