I want to draw text on a template image in UWP (for Windows 10), and then be able to save the image (so the user could print or share it).
I have played around with the canvas control and even the Win2D package from nuget. Any suggestions as to what the best way to do this are appreciated. Sample code of where I left off is below.
XAML
<Page
x:Class="DrawTextExample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DrawTextExample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
mc:Ignorable="d">
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Button Name="btnSaveImage" Content="Save the image" Margin="10" Click="btnSaveImage_Click" />
<Grid Name="MyCreatedImage">
<Image Name="imgName" Stretch="UniformToFill" Source="Assets/HelloMyNameIs.jpg" />
<TextBlock Name="lblName" Text="McFly" Margin="20,100,20,20" FontSize="36"/>
</Grid>
</StackPanel>
Code Behind
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
namespace DrawTextExample {
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private async void btnSaveImage_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) {
var bitmap = new RenderTargetBitmap();
await bitmap.RenderAsync(MyCreatedImage);
}
}
}