I have already read a lot of posts on Stack about image resizing and quality reducing, but non of them has been about reducing quality to certain physical disk space
I have a code that takes a picture:
private async void TakeAPhoto_Click(object sender, RoutedEventArgs e)
{
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
StorageFile photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
if (photo != null)
{
}
}
Now i need to send the data to the server, but before, i need to ensure that the photo is not more than 3 MB.
So i do this:
BasicProperties pro = await photo.GetBasicPropertiesAsync();
if (pro.Size < 3072)
{
// SEND THE FILE TO SERVER
}
else
{
// DECREASE QUALITY BEFORE SENDING
}
So the question is about ELSE block
Is there a better or maybe i have missed some built-in approach to fit image into the certain amount of megabytes by decreasing it's quality?
Because doing this:
while (pro.Size <= 3072)
{
photo = // some logic to decrease quality on 10%
}
Doesn't really look good.
Just Create one function :
And then call this function in your else block as below you will get same image with reduced size :