WebP: Reading from ImageInputStream with unknown length does not decode (produces black image)
See original GitHub issueI tried to convert webP file to JPG with TwelveMonkeys imageIO 8.2 version. My output jpg image turn black.
String targetFileName = path + "../out/" + fileName;
targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf(".")) + ".jpg";
File outputFile = new File(targetFileName);
InputStream is = new FileInputStream(inputFile);
ImageInputStream iis = ImageIO.createImageInputStream(is);
BufferedImage originalImage = ImageIO.read(iis)
BufferedImage newImage = new BufferedImage(Math.round(newSize[0]), Math.round(newSize[1]), BufferedImage.TYPE_INT_RGB);
Image scaleImage = originalImage.getScaledInstance( Math.round(newSize[0]-diffAdd), Math.round(newSize[1]),Image.SCALE_DEFAULT);
Graphics g = newImage.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, Math.round(orgWidth + 2 * diffAdd), Math.round(newSize[1])); //Adds white bar on right and left.
g.drawImage(scaleImage, Math.round(diffAdd), 0, null);
g.dispose();
OutputStream os = new FileOutputStream(outputFile);
ImageOutputStream ios = ImageIO.createImageOutputStream(os);
ImageIO.write(newImage, "jpg", ios);
I added following jars common-image-3.8.2.jar common-io-3.8.2.jar common-lang-3.8.2.jar imageio-core-3.8.2.jar imageio-jpeg-3.8.2.jar imageio-metadata-3.8.2.jar imageio-tiff-3.8.2.jar imageio-webp-3.8.2.jar
Issue Analytics
- State:
- Created a year ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
TwelveMonkeys - Bountysource
WebP : Reading from InputStream with unknown length does not decode (produces black image) ... scaled images are black on the right side...
Read more >Can not load transparent lossy WebP texture #613 - GitHub
Hi Describe the bug I can not load the transparent WebP texture lossy ... PNG to WebP converter) BufferedImage image = ImageIO.read(new ...
Read more >Unable to read JPEG image using ImageIO.read(File file)
read (File file) - it throws an exception with the message "Unsupported Image Type". I have tried other JPEG images, and they seem...
Read more >Source Code for ExifInterface.java - AndroidX Tech
CRC32; /** * This is a class for reading and writing Exif tags in various image file formats. * <p> * Supported for...
Read more >Untitled
Tom taus pictures, 2000 grand voyager, Regents park rose garden map, Avocet 1202, ... Sonidos fantasmales gratis, Is not eating for two days...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Odd…
I can reproduce the black image issue using:
However, using:
Or:
…reads the image as it should. 🤔
You can use one of these forms as a workaround for now, but of course, all three versions should work exactly the same… I’ll investigate.
Okay,
I’ll try to look into it over the holidays.