dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22k stars 1.72k forks source link

Android skia canvas.DrawImage has no effect with SkiaBitmapExportContext #10575

Open philipag opened 1 year ago

philipag commented 1 year ago

Description

When using SKCanvasView, one can use canvas.DrawImage and image is displayed. However, when using SkiaBitmapExportContext.Canvas.DrawImage, nothing is rendered into the canvas.

Please see the attached sample for details. It saves the file badOutputWithoutImage.png which should contain the Android robot image but does not. It only shows the white background which was rendered into the canvas.

skiaBug.zip

Steps to Reproduce

  1. Build the attached sample, build and run on an emulator.
  2. Use Android Studio to navigate to and view the output file "badOutputWithoutImage.png"
  3. The file does not contain the android robot image that was painted into the canvas (it should).

Link to public reproduction project repository

attached

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 12

Did you find any workaround?

no

Relevant log output

No response

mattleibow commented 1 year ago

SkiaBitmapExportContext is part of maui graphics so the bug is there.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ksd050 commented 1 year ago

This has been outstanding for some time now, is there any hope that it will be resolved? Alternatively, has anyone found a workaround?

homeyf commented 1 year ago

Verified this issue with Visual Studio Enterprise 17.8.0 Preview 1.0. Can repro on android with sample project. skiaBug.zip image

softlion commented 1 month ago

The cause of this issue is that code in SkiaCanvas.DrawImage used by MySkiaBitmapExportContext, which tries to convert the IImage into a SkiaImage.

But most of the time IImage is a PlatformImage, not a SkiaImage. The above conversion results becomes null, and the whole call is a noop.

A simple fix would be to replace the cast by SkiaImage into a cast by PlatformImage.

image

image

softlion commented 1 month ago

A temporary workaround:


#if ANDROID
using SkiaSharp.Views.Android;
#elif IOS
using SkiaSharp.Views.iOS;
#endif

            if (image is not SkiaImage && image is PlatformImage platformImage)
            {
                var platformRepresentation = platformImage.PlatformRepresentation;
                var newImage = new SkiaImage(SKBitmap.FromImage(platformRepresentation.ToSKImage()));
                image.Dispose();
                image = newImage;
            }