skbitmap encode as stream in maui is not properly working (Android 12 samsung galaxy A10)

Satya 105 Reputation points
2023-08-03T14:07:51.6233333+00:00
 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;
    }


SKBitmap photoBitmap = RotateBitmap(SKBitmap.Decode(streamimg));
Stream rotatedStream = SKImage.FromBitmap(photoBitmap).Encode().AsStream();

Getting wrong stream after encoding and when binding the stream to image, getting black screen.
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,370 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 74,086 Reputation points Microsoft Vendor
    2023-08-04T06:26:52.6133333+00:00

    Firstly, please run your code in the android emulator, will you get the same issue?

    How did you bind the stream to image? I use following code and android 11 emulator, it is working without any issue.myImage.Source = ImageSource.FromStream(()=>rotatedStream);.

    And please make sure you have installed following nugget packages in your project.

        <ItemGroup>
          <PackageReference Include="SkiaSharp" Version="2.88.3" />
          <PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.3" />
          <PackageReference Include="SkiaSharp.Views.Maui.Controls.Compatibility" Version="2.88.3" />
          <PackageReference Include="SkiaSharp.Views.Maui.Core" Version="2.88.3" />
        </ItemGroup>
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.