question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebP: Reading from ImageInputStream with unknown length does not decode (produces black image)

See original GitHub issue

I 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:closed
  • Created a year ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
haraldkcommented, Apr 19, 2022

Odd…

I can reproduce the black image issue using:

File inputFile = new File(args[0]);
InputStream is = new FileInputStream(inputFile);
ImageInputStream iis = ImageIO.createImageInputStream(is);
BufferedImage originalImage = ImageIO.read(iis);

However, using:

File inputFile = new File(args[0]);
BufferedImage originalImage = ImageIO.read(inputFile);

Or:

File inputFile = new File(args[0]);
ImageInputStream iis = ImageIO.createImageInputStream(inputFile);
BufferedImage originalImage = ImageIO.read(iis);

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

1reaction
haraldkcommented, Apr 14, 2022

Okay,

I’ll try to look into it over the holidays.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found