在图像上保存文本块

Saving textBlock on image

我找到了很多 Windows Phone 8/8.1 的示例,但我似乎找不到 Window 10 UWP 的示例。

所以我需要的是图像上的可移动文本块。我只是好像不知道如何加载图像,写一些文字然后保存。

我目前拥有的代码[不起作用]

//first, create a dummy bitmap just to get a graphics object
            Image img = new Bitmap(1, 1);
            Graphics drawing = Graphics.FromImage(img);

            //measure the string to see how big the image needs to be
            SizeF textSize = drawing.MeasureString(text, font);

            //free up the dummy image and old graphics object
            img.Dispose();
            drawing.Dispose();

            //create a new image of the right size
            img = new Bitmap((int)textSize.Width, (int)textSize.Height);

            drawing = Graphics.FromImage(img);

            //paint the background
            drawing.Clear(backColor);

            //create a brush for the text
            Brush textBrush = new SolidBrush(textColor);

            drawing.DrawString(text, font, textBrush, 0, 0);

            drawing.Save();

            textBrush.Dispose();
            drawing.Dispose();

您需要 RenderTargetBitmap 这里是 Windows Store 应用程序 (8.1) 的示例并且对 UWP 应用程序仍然有效 http://social.technet.microsoft.com/wiki/contents/articles/20648.using-the-rendertargetbitmap-in-windows-store-apps-with-xaml-and-c.aspx

这是带有 RenderTargetBitmap 的 UWP 应用程序的 MSDN 文档 https://msdn.microsoft.com/library/windows/apps/dn298548

我建议您将文本块放在网格(容器)中并按照示例进行操作。

此致