How do you know that the size is around 2.65MB? Can you open the resulting bytes? Does it look okay?
–
ThiloJan 19 '12 at 12:57

1

Are you sure the input image really is in PNG format?
–
PerceptionJan 19 '12 at 12:58

@Thilo - The image is an uploaded image from my local machine. I checked the file both on my local machine and on the server. It has a size of 2.65MB. I am using BufferedImage image = ImageIO.read(inputFile); to create the image object from the file. Yes, the byte[] stored looks OK except for the size.
–
sure_renderJan 19 '12 at 13:08

If you have the uploaded PNG image file, why don't you just use that one? If on the other hand, you manipulate the image, the result could compress differently (much differently apparently, maybe there are some settings to play with).
–
ThiloJan 19 '12 at 13:10

Both of you were right. The uploaded image was in jpg format, so changed the code to use "jpg" and "png" based on the file type accordingly. However, the size now shows 0.5MB now, which is way lower than the actual size. I'm pretty sure I am losing the quality of the image. The reason that I am having to do this is because I need to store the image on the Amazon S3 server which accepts the data only in byte[] format. Do you guys see any solution?
–
sure_renderJan 19 '12 at 13:15