Microsoft.Maui.Graphics icon indicating copy to clipboard operation
Microsoft.Maui.Graphics copied to clipboard

How to load a image on the windows platform?

Open BlueCapo opened this issue 2 years ago • 2 comments

The PlatformImage type isn't supported on Windows. PlatformImage.FromStream(stream),it is unusable. I can't find any solution. Is there any other solution?

BlueCapo avatar Feb 10 '23 03:02 BlueCapo

private void LoadImages()
{
IImage image = null;

#if WINDOWS

    Assembly assembly = GetType().GetTypeInfo().Assembly;
    var service = new Microsoft.Maui.Graphics.Win2D.W2DImageLoadingService();
    using (Stream stream = assembly.GetManifestResourceStream("HappySokoban.Resources.Images.box.jpg"))
    {
        image = service.FromStream(stream, ImageFormat.Jpeg);
    }        

#else

    Assembly assembly = GetType().GetTypeInfo().Assembly;
    using (Stream stream = assembly.GetManifestResourceStream("HappySokoban.Resources.Images.box.jpg"))
    {
        image = PlatformImage.FromStream(stream);
    } 

#endif }

seabluescn avatar Apr 17 '23 09:04 seabluescn

It also don't work with skiasharp drawbitmap on Platform-Windows.

TFreudi1 avatar Jun 02 '23 12:06 TFreudi1