簡體   English   中英

UIElement 到圖像文件 (WP7)

[英]UIElement to image file (WP7)

我有一個StackPanel ,其中包含一些我想放入圖像文件(例如 PNG)的Rectangles 我正在 Windows Phone 7 上開發這個,我在互聯網上找到的大部分信息都不適用於(我認為)WP7。

我認為System.Windows.Media.Imaging命名空間是關鍵,但我不知道從哪里開始。

這基本上是我想要做的:

StackPanel stack = new StackPanel();
List<Rectangle> recList = new List<Rectangle>();

recList添加一些矩形

foreach(var x in recList)
     stack.Children.Add(x);

然后將堆棧面板保存到圖像文件...

您可以使用WriteableBitmap來保存圖像。

WriteableBitmap wb = new WriteableBitmap(stack, null);
MemoryStream ms = new MemoryStream();

wb.SaveJpeg(ms, myWidth, myHeight, 0, 100);

您可以改為將MemoryStream更改為獨立存儲 stream。 如果要在 Image 控件中顯示上述MemoryStream

 BitmapImage bmp = new BitmapImage();
 bmp.SetSource(ms);
 image1.Source = bmp;

或者,保存到獨立存儲:

using (var isoFileStream = new IsolatedStorageFileStream("myPicture.jpg", FileMode.OpenOrCreate, IsolatedStorageFile.GetUserStoreForApplication())) 
{                     
    wb.SaveJpeg(isoFileStream, myWidth, myHeight, 0, 100);                    
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM