I\'m trying to compress image taken from camera to 250kb size in Xamarin.Forms. I found ways to do that in dependency service but I want it without dependency service (pure
I also had this same problem. Please check here as I believe you will find the solution.
https://xamarincodes.com/2020/04/05/image-compression-in-xamarin-forms/
I used Xam.Plugin.Media – setting the compression quality to take photos and compress as well.
Here is a sample
private async void cmdCameraPhotograph_Clicked(object sender, EventArgs e)
{
if (CrossMedia.Current.IsTakePhotoSupported)
{
var file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
{
Directory = "Photographs",
SaveToAlbum = true,
CompressionQuality = 40,
CustomPhotoSize = 35,
PhotoSize = PhotoSize.MaxWidthHeight,
MaxWidthHeight = 2000,
DefaultCamera = CameraDevice.Rear
}).ConfigureAwait(true);
if (file != null)
{
}
}
else
{
await DisplayAlert("Not Supported", "Your device does not support this feature.", "OK. Understood")
.ConfigureAwait(true);
}
}
You can also get the file from the Gallery
var file = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
{
CompressionQuality = 40,
CustomPhotoSize = 35,
PhotoSize = PhotoSize.MaxWidthHeight,
MaxWidthHeight = 2000
}).ConfigureAwait(true);