Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working alternative for PlatformImage for Maui.Graphics.IImage for Windows? #6742

Closed
janseris opened this issue May 2, 2022 · 10 comments
Closed
Labels
area-controls-image Image control platform/windows 🪟 t/bug Something isn't working

Comments

@janseris
Copy link

janseris commented May 2, 2022

Description

https://docs.microsoft.com/en-us/dotnet/maui/user-interface/graphics/images
This sample shows how to load and work with image. The docs are not fully cross-platform.
I need user to select an image and resize it on Windows. PlatformImage is not available on Windows.
What is the suggested solution (working IImage implementation) for Windows?

image

image

Moreover, the docs say this:

Image loading functionality is provided by the GraphicsService class. Images can be loaded from a stream by the LoadFromStream method, or from a byte array using the LoadImageFromBytes method.

I cannot find any of these mentioned classes or methods. Is that a leftover from previous Preview version?

Thank you

Steps to Reproduce

Try get an IImage on Windows

Version with bug

Release Candidate 2 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

all?

Did you find any workaround?

not sure because SkiaImage isn't finished
image

other possible alternatives (have to check):
image

Relevant log output

No response

@janseris janseris added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels May 2, 2022
@janseris janseris changed the title No alternative for PlatformImage on Windows? No available for Maui.Graphics.IImage implementation for Windows? May 2, 2022
@janseris janseris changed the title No available for Maui.Graphics.IImage implementation for Windows? Alternative for PlatformImage for Maui.Graphics.IImage for Windows? May 2, 2022
@janseris janseris changed the title Alternative for PlatformImage for Maui.Graphics.IImage for Windows? Working alternative for PlatformImage for Maui.Graphics.IImage for Windows? May 2, 2022
@drasticactions
Copy link
Contributor

I might be reading this wrong but I think for Windows, PlatformImage is W2DImage (https://github.com/dotnet/Microsoft.Maui.Graphics/blob/main/src/Microsoft.Maui.Graphics.Win2D.WinUI.Desktop/W2DImage.cs). And instead of using PlatformImage, you should use IImage instead, since that's the base image type for all of them.

@mattleibow does that sound right? It does seem weird that there is no direct PlatformImage for Windows that I can see.

@Eilon Eilon added the area-image Image loading, sources, caching label May 2, 2022
@janseris
Copy link
Author

janseris commented May 2, 2022

@drasticactions
The class is not public and parts of it are not implemented.
image

image

similar for all other IImage implementations: SkiaImage, GDIImage, DXImage, GtkImage, - none of them is fully implemented.
The only fully implemented class for IImage interface is PlatformImage.

And instead of using PlatformImage, you should use IImage instead, since that's the base image type for all of them.

I would work with IImage however I have to construct it first from byte[] or Stream / MemoryStream and for that, I need the concrete implementation class.
Something like IImage image = new ConcreteImage(...) because the IImage interface hasn't got any static methods such as FromStream() or FromByteArray() etc.

@jfversluis jfversluis removed the s/needs-verification Indicates that this issue needs initial verification before further triage will happen label May 2, 2022
@mattleibow
Copy link
Member

I believe you access this via the IImageLoadingService

https://github.com/dotnet/Microsoft.Maui.Graphics/blob/main/src/Microsoft.Maui.Graphics/IImageLoadingService.cs

Each platform has this service and you can either use DI or use the service directly to load images. This way, it doesn't matter what the platform image types are. Some method parameters or property types on some some images are platform specific so there is not a good way to expose this in a cross platform way.

So we opted for a service that you request images from.

@Redth Redth closed this as completed May 3, 2022
@janseris
Copy link
Author

janseris commented May 6, 2022

@mattleibow
There are currently three implementations of IImageLoadingService available in the main branch of Maui.Graphics.

Microsoft.Maui.Graphics.Platform.PlatformImageLoadingService

  • return PlatformImage.FromStream(stream, formatHint);

Microsoft.Maui.Graphics.Win2D.SkiaImageLoadingService

  • return W2DImage.FromStream(stream, formatHint);

Microsoft.Maui.Graphics.Skia.SkiaImageLoadingService

  • return SkiaImage.FromStream(stream, formatHint);

Is Microsoft.Maui.Graphics.Win2D.SkiaImageLoadingService misnamed?

Which is the right service implementation for Windows - SkiaImageLoadingService or SkiaImageLoadingService?

@mattleibow
Copy link
Member

Ooh, looks like a typo in the service name... Use the one from the win2d namespace. I'll fix that and get it in for rc3.

Sorry about that confusion

@mattleibow
Copy link
Member

I think RC is too late to change now 😢 @Redth?

However, this is fixed in this PR for the servicing update with no breaking changes for you: dotnet/Microsoft.Maui.Graphics#420

@janseris
Copy link
Author

janseris commented May 7, 2022

@mattleibow well even if the Windows class name Is fixed, the class Is useless, it cannot load any image. Fails with something not registered during runtime
dotnet/Microsoft.Maui.Graphics#422

And if it can load the image, can Win2DImage resize or downsize? I have seen just empty code in MAUI graphics repo.

@mattleibow
Copy link
Member

Thanks for that issue, I will have a look and see if I can get to this soon.

@janseris
Copy link
Author

janseris commented May 11, 2022

Thanks for that issue, I will have a look and see if I can get to this soon.

Thank you, btw which platform does the Microsoft.Maui.Graphics.Skia.SkiaImageLoadingService and SkiaImage fit?
For Android there is probably PlatformImage and for Windows, there is probably Win2D.
Is it the Mac and iOS implementation and thus I should not care about it when using Windows and Android only?
I think this is not mentioned anywhere -> which implementation of IImageLoadingService should be used for which platform.
I have only deduced that PlatformImage is for Android from the tutorials code and Win2D for Windows from the Win in the name.

Each platform has this service and you can either use DI or use the service directly to load images.

@mattleibow
Copy link
Member

The Skia* things is an alternative implementation that works across all platforms. You can either draw using win2d or skia.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 10, 2022
@Eilon Eilon added area-controls-image Image control and removed area-image Image loading, sources, caching labels May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-image Image control platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants