0

I'm trying to rotate the image and save the rotated image to the database in Xamarin Form. However, after converting to byte arrays, both original and rotated images have the same result. Convert RotatedImage to BytesArray:

public static SKImage Rotate(byte[] imageBytesArray)
{
    using (var bitmap = SKBitmap.Decode(imageBytesArray))
    {
        var rotated = new SKBitmap(bitmap.Height, bitmap.Width);

        using (var surface = new SKCanvas(rotated))
        {
            surface.Translate(rotated.Width, 0);
            surface.RotateDegrees(90);
            surface.DrawBitmap(bitmap, 0, 0);
        }
        SKImage image = SKImage.FromBitmap(bitmap);
        //return rotated;
        return image;
    }
}

This method returns the modified bytes array for the rotated Image, but the image is not actually rotated.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Kranatos
  • 107
  • 2
  • 10
  • 2
    rotating the image **control** on the screen does not do anything to the underlying data. You either need to manipulate the underlying bits in the image data, or set the EXIF data to indicate the image is rotated. – Jason Apr 25 '23 at 20:08
  • Thanks for replying ! Is there any way to Flip Image that changes the bit in image data in Xamarin Forms? Most of flip methods in C# cannot be used in Xamarin Form. – Kranatos Apr 25 '23 at 22:53
  • Use SkiaSharp. See the linked question – Jason Apr 25 '23 at 23:18
  • Okay, I see in the link that SKSharp could return the different bytes array for the image, but the image is not actually rotated: using (var surface = new SKCanvas(rotated)) { surface.Translate(rotated.Width, 0); surface.RotateDegrees(90); surface.DrawBitmap(bitmap, 0, 0); } Did you mean this method? – Kranatos Apr 27 '23 at 01:01
  • 1
    you are returning the original `bitmap`, not `rotated` – Jason Apr 27 '23 at 01:08
  • Yeah, you're right. It's my bad. Thanks for your help! – Kranatos Apr 27 '23 at 04:58

0 Answers0