Can we downscale the image in Java without changing the dimensions of the image?
By using BufferedImage, Graphics2D, RenderingHints I can downsize the image with the dimensions I am giving. But if I keep the dimensions same, whatever image I am getting after calling drawimage() [dimensions are same], Is that image different from the original image?
We can. Use Graphics2D.drawRenderedImage function.
posted 8 years ago
Thanks Andrey :-)
I did not get the chance to look at the method suggested by you. I am very new to Graphics2D. I tried to use drawImage method of Graphics2D.
My requirement is I need to scaledown (or compress/reduce the size(KB) of the image) the image to some size (say 50000 bytes for my application) keeping the dimensions same.
Code I have written till now is
the way I am calling the above method is
(I have hard coded the dimensions currently because my original image is 800*600)
Now I finding on this code is:-
Image is getting downscaled to some size (dimensions same). I tried with few images. Getting different size for different images.
For example 1) My original image was around 38000 bytes and the new image after invoking the above code is around 6000 bytes.
2) My original image was around 64000 bytes and the new image after invoking the above code is around 53000 bytes.
My question is - Can not I control the size of image (keeping the dimesnions same). I want to dowmscale the image (keeping the dimensions same) to 50000 bytes if the size of the original image is more than 50000 bytes.
Carey Brown wrote:a) I don't see where you are printing the AFTER size, and b) if you are keeping the original image dimensions, why would you expect the size to be any different?
Hi, This is not a complete code. This is just a part of my complete program.
By size I mean the size of image in bytes. We can compress or downscale the image even by keeping the dimensions same.
Thanks anyways :-)
A BufferedImage is not compressed, if it were to be saved as a JPG file the file itself would then be compressed, but that's not what you're measuring.
"Downscaling" usually infers re-sampling to a smaller dimension which would not keep the dimensions the same.