Reputation: 714
I'm trying to use xamarin.forms plugin.media plugin to take a photo and save it at a specific size. Here's my code:
private async void ButtonPhoto_OnClicked(object sender, EventArgs e)
{
if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
{
var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
PhotoSize = PhotoSize.Custom,
MaxWidthHeight = 250,
Directory = "MyFolder",
Name = _item.Id + ".jpg",
SaveToAlbum = true
};
var file = await CrossMedia.Current.TakePhotoAsync(mediaOptions);
}
}
The actual saving of the photo to the desired folder works, however, the resizing options are being ignored. I want the picture width to be set at no more than 250 pixels. Can anyone spot where I'm going wrong?
edit 1:
I also tried the following, but still no joy:
var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
PhotoSize = PhotoSize.MaxWidthHeight,
MaxWidthHeight = 250,
Directory = "MyFolder",
Name = _item.Id + ".jpg",
SaveToAlbum = true
};
edit 2:
Tried the following using RotateImage as suggested, but still no joy:
var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
PhotoSize = PhotoSize.Custom,
RotateImage = true,
CustomPhotoSize = 5,
Directory = "MyFolder",
Name = _item.Id + ".jpg",
SaveToAlbum = true
};
edit 3:
Tried setting RotateImage with MaxWidthHeight, but still not working:
var mediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
PhotoSize = PhotoSize.MaxWidthHeight,
MaxWidthHeight = 150,
RotateImage = true,
Directory = "MyFolder",
Name = _item.Id + ".jpg",
SaveToAlbum = true,
CompressionQuality = 75
};
Upvotes: 1
Views: 2582
Reputation: 280
The SaveToAlbum option always stores the original photo in full resolution locally.
The image resize is only applied in the returned MediaFile.GetStream() data.
So you could deactivate SaveToAlbum and store it manually using the provided data stream.
In my case I had to send the image over a network connection. The behaviour full size on local storage and resized in app stream was handy in my case.
Upvotes: 1