So you have a couple of problems:
- How to draw using the
InkCanvas control over Image . - How to save the results in a file.
In this example, I am using a simple UWP application that assumes that you have a sample.jpg file in your Assets folder and you have a Pictures feature in your manifest.
To solve the first problem, just put both InkCanvas and Image in the same container (e.g. Grid ), but remember that the order matters :
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid> <Image Source="/Assets/sample.jpg"></Image> <InkCanvas x:Name="ink"></InkCanvas> </Grid> <Button Content="Save" Width="100" Height="25" HorizontalAlignment="Center" VerticalAlignment="Center" Click="BtnSave_Click"/> </StackPanel>
If you first put InkCanvas (for example, in the example), this will not work. However, if put InkCanvas last - everything works fine, and you can draw your image.
Now, to solve the second problem, you need to use Win2D (install the nuget package Win2D.uwp), since the standard RenderTargetBitmap will not display the contents of InkCanvas . First draw the original image (take the image from the original source directly, for example, from the source file), then draw the contents of your ink canvas above it. Full MainPage code (if you add xaml above, you will have a full working sample):
public sealed partial class MainPage : Page { public MainPage() { this.InitializeComponent();
Evk
source share