2016-02-26 95 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