Hello,
I faced exactly the same issue.
Is there any solution for this out there?
Thanks.
Sebastian.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How can I rotate the image (is byte[]) captured by CamerView (Xamarin Community Toolkit) since rotation doesn't have a setter?
Hello,
I faced exactly the same issue.
Is there any solution for this out there?
Thanks.
Sebastian.
And using SkiaSharp when I convert SKBitmap back to bytes[] has not undergone any rotation. But I need a byte[].
@Andrea Farina Try to get the stream for the ImageSource
and then use SKBitmap.Decode(stream)
command to generate a SKBitmap
iobject.
Here is the related code, you could refer to it:
private void CameraView_MediaCaptured(object sender, Xamarin.CommunityToolkit.UI.Views.MediaCapturedEventArgs e)
{
StreamImageSource streamImageSource = (StreamImageSource)e.Image;
System.Threading.CancellationToken cancellationToken = System.Threading.CancellationToken.None;
Task<Stream> task = streamImageSource.Stream(cancellationToken);
Stream stream = task.Result;
SKBitmap photo = RotateBitmap(SKBitmap.Decode(stream));
img.Source = ImageSource.FromStream(() => SKImage.FromBitmap(photo).Encode().AsStream());
}
SKBitmap RotateBitmap(SKBitmap bitmap)
{
SKBitmap rotatedBitmap = new SKBitmap(bitmap.Height, bitmap.Width);
using (var surface = new SKCanvas(rotatedBitmap))
{
surface.Translate(rotatedBitmap.Width, 0);
surface.RotateDegrees(90);
surface.DrawBitmap(bitmap, 0, 0);
}
return rotatedBitmap;
}