Windows Phone 7 截取當前屏幕保存圖像的代碼

 導入如下命名空間: ide

using System.Windows.Media.Imaging;
using System.IO;

using Microsoft.Xna.Framework.Media; spa

 

所有代碼以下:code

 1         public   void  CaptureScreen( object  sender, EventArgs e) 
 2          {
 3              WriteableBitmap bmp  =   new  WriteableBitmap( 480 800 );
 4              bmp.Render(App.Current.RootVisual,  null );
 5              bmp.Invalidate();
 6 
 7              MemoryStream stream  =   new  MemoryStream();
 8              bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight,  0 80 );
 9              stream.Seek( 0 , SeekOrigin.Begin);
10 
11              MediaLibrary library  =   new  MediaLibrary();
12               string  fileName  =   " ScreenShot_ "   +  DateTime.Now.ToString( " yyyy-mm-dd_hh:mm:ss " );
13              library.SavePicture(fileName, stream);
14              stream.Close();
15 
16 
17              Dispatcher.BeginInvoke(()  =>  
18              {
19                  PictureCollection picCollection  =  library.Pictures;
20                   foreach  (Picture item  in  picCollection)
21                  {
22                       if  (item != null )
23                      {
24                          BitmapImage bitmap  =   new  BitmapImage();
25                          bitmap.SetSource(item.GetImage());
26                          ScreenShot.Source  =  bitmap;
27                          PicName.Text  = " 圖片名稱 : " +  item.Name;
28                      }
29                     
30                  }
31              });
32 
33 
34           

35     }blog

 

 調用該方法後獲得的效果以下:圖片

 

相關文章
相關標籤/搜索