简体   繁体   中英

C# Limit image size under 150kb

We have created a software in windows c# for cropping image as per the mouse drawn rectangle.

The images are of various dimensions and filesize.

When the user will save the image we want to keep the filesize under 150Kb.

For any file over 150kb We are compressing the images while saving using image interpolation mode.

If still the size is above 150kb the next step we want is to to reduce file dimensions proportionally until it's under 150 kB.

We have created a loop to reduce the image dimensions by 5 percent and then we save the file and check size and continue until the 150kb.

As we will be working on very high number of images want to confirm if this is the right way of doing it? Or someone from stack overflow suggest a better method.

Will share the code if required.

PS saving image each time just to check the size doesn't feel correct.

I would suggest just to calculate image size yourself. Knowing format compression and dimension you could more or less predict size of image. You could check this link as an example

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM