Hi, I'm trying to implement picture on profile page in my app, so I'm using Xamarin Labs for MediaPicker, to take or select images, and then using Image Resizer, I call resize after getting picture from MediaPicker, and get System.ArgumentException: Reading would overrun buffer on read bytes from stream.
here is what I'm trying to do:
private byte[] GetResizedImage(Stream str, int screenWidth, int screenHeight)
{
var array = new byte[] {};
str.Position = 0;
str.Read(array, 0, (int)str.Length - 1); // **EXCEPTION HERE**
if (ImageResizer == null)
return array;
try
{
return ImageResizer.ResizeImage(array, screenWidth, screenHeight);
}
catch (Exception)
{
return array;
}
}
private async Task SelectPicture()
{
mediaPicker = DependencyService.Get<IMediaPicker>();
imageSource = null;
var mediaFile = await mediaPicker.SelectPhotoAsync(new CameraMediaStorageOptions
{
DefaultCamera = CameraDevice.Front,
MaxPixelDimension = 1,
PercentQuality = 2,
});
var image = GetResizedImage(mediaFile.Source, 1024, 400);
myImage.Source = ImageSource.FromStream(() => new MemoryStream(image)); ;
profileButton.Source = ImageSource.FromStream(() => new MemoryStream(image));
}
does anyone know how to fix this?