I have a byte array that contains a jpeg image. I was just wondering if it is possible to reduce its size?
Edit: Ok. I acknowledged my mistake. Then my question is how can I reduce the quality of the image comes from a byte array.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Please understand that there is no free lunch. Decreasing the size of a JPEG image by increasing the compression will also decrease the quality of the image. However, that said, you can reduce the size of a JPEG image using the
Imageclass. This code assumes thatinputBytescontains the original image.Now
outputBytescontains a recompressed version of the image using a different JPEG quality.By decreasing the
jpegQuality(should be in the range 0-100) you can increase the compression at the cost of lower image quality. See theEncoder.Qualityfield for more information.Here is an example where you can see how
jpegQualityaffects the image quality. It is the same photo compressed using 20, 50 and 80 as the value ofjpegQuality. Sizes are 4.99, 8.28 and 12.9 KB.Notice how the text becomes “smudged” even when the quality is high. This is why you should avoid using JPEG for images with uniformly colored areas (images/diagrams/charts created on a computer). Use PNG instead. For photos JPEG is very suitable if you do not lower the quality too much.