Closed JoeJErnst closed 10 years ago
@JoeJErnst imgscalr actually only operates on uncompressed raw image data stored in the BufferedImage - the actual size and quality of the result is determined by the GIF/BMP/JPG/PNG encoder you are using from Java to recompress the data to a file.
That said, I have a FEELING what is going on here is you are reading in a JPG and writing out a PNG - is that right?
If not, then the other thing that might explain it is you are reading in a JPG and writing back out a very high quality JPG by changing the ImageWriterParams.
If THAT's not right either, then I'll stop guessing and just ask you to show me your reading and writing code and clarify the input and output file :)
BINGO! You nailed it with the PNG hypothesis. ;-) I had inadvertently set the type to png here:
ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(image, "png", os);
When i changed that to "jpg" my resized image file size went down to 67k.
Thanks for the prompt reply; you saved my day!
Glad I could help!
I have noticed that the file size grows dramatically when resizing an image. This is most noticeable when resizing to a dimension very close (or equal to) the original size of the image.
I am using this code:
Scalr.resize(ImageIO.read(inputStream), 1024);
When I start with a file that is 103kb on disk, (1222x574 px) it ends up being over 800k after it is resized to a final dimension of 1024x481 px. Is this expected? ( I have tried this with several JPGs from different sources and the results are consistent)