I have an InkCanvas in my UWP app, and would like to display an image (ideally as part of the Canvas, but otherwise, overlay it in some way (the idea being that I can save the changed image back to the image file). WPF seems to allow the InkCanvas to have children, but in UWP that doesn't seem to be possible. I've tried the following:
<InkCanvas x:Name="drawInkCanvas">
<Image Source="{Binding DrawingImage}"/>
</InkCanvas>
But that doesn't work; I've also tried this:
<Grid Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<InkCanvas x:Name="drawInkCanvas" Opacity=".5"/>
<Image Source="{Binding DrawingImage}" Opacity=".5"/>
</Canvas>
Which, to be fair, I didn't have very high hopes for; anyway, although it does, kind of work, it makes both the image and the InkCanvas look wrong and, obviously, doesn't allow me to save the resulting image.
Ideally, there would be a background image or something similar. Is there anything that I can use to achieve this; I'm approaching the opinion that I may have to replace the InkCanvas with a standard canvas and then re-write all the InkCanvas functionality!
So you have couple of problems:
InkCanvas
overImage
control.I'll use simple UWP app in this example, which assumes that you have "sample.jpg" file in your Assets folder, and you have "Pictures Library" capability in your manifest.
To solve first problem, just put both
InkCanvas
andImage
into same container (likeGrid
), but remember that order matters:If you put
InkCanvas
first (like you did in question example) - it won't work. However if putInkCanvas
last - all works fine and you can draw over your image.Now to solve second problem you need to use Win2D (install nuget Win2D.uwp package), because standard
RenderTargetBitmap
won't renderInkCanvas
contents. First draw your original image (take image from original source directly, that is from original file for example), then draw contents of your ink canvas over it. Full code of MainPage (if you add xaml above you will have complete working sample):