我在Windows Phone 8 / 8.1中找到了很多示例,但我似乎无法为Window 10 UWP找到一个。
所以我需要的是图像上的可移动textBlock。我似乎不知道如何加载图像,写一些文本然后保存它。
Code I目前有[不起作用]
//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();
答案 0 :(得分:1)
这里需要RenderTargetBitmap是Windows应用商店应用(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
我建议您将文本块放在Grid(容器)中并按照示例进行操作。
最好的问候