EDIT:
They removed the CompositionImage in the last build ...
I would like to know the difference between Win2D CanvasBitmap
and Microsoft.UI.Composition CompositionImage
.
In both case I was able to display images but I don't really know/understand the difference between the two approach.
The CanvasBitmap
approach:
XAML:
<xaml:CanvasControl Draw="OnDraw" />
Code:
private void Onraw(CanvasControl sender, CanvasAnimatedDrawEventArgs e)
{
var image = await CanvasBitmap.LoadAsync(...);
e.DrawingSession.DrawImage(...);
}
The CompositionImage
approach:
XAML:
<Grid x:Name="Host" />
Code:
ContainerVisual rootVisual =
(ContainerVisual)ElementCompositionPreview.GetContainerVisual(this.Host);
Compositor compositor = rootVisual.Compositor;
CompositionGraphicsDevice device = compositor.DefaultGraphicsDevice,
CompositionImage image = device.CreateImageFromUri(...);
ImageVisual content = Compositor.CreateImageVisual();
content.Image = image;
rootVisual.Children.InsertAtTop(content);
What's the difference? What is the best approach?
To put thing in the context, I have an application that displays a lot of small images. I need the app to be low on memory and to draw fast the images.
Thanks, Adrien.