2016-02-26 92 views
0

我发现很多Windows Phone 8/8.1的例子,但我似乎无法找到一个用于Window 10 UWP的例子。在图像上保存textBlock

所以我需要的是一个可移动的textBlock在图像上。我似乎不知道如何加载图像,写入一些文本然后保存。

代码我现在有[不起作用]

//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(); 

回答

1

你需要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

我建议您将您的textblock放入网格(容器)中,并按照t他的例子。

最好的问候

+0

请标记此答案,如果它对您有用!谢谢! – RicardoPons