Windows Phone 7 截取当前屏幕保存图像的代码

it2022-05-09  27

导入以下命名空间:

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

using Microsoft.Xna.Framework.Media; 

 

全部代码如下:

 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     }

 

 调用该方法后得到的效果如下:

 

转载于:https://www.cnblogs.com/TerryBlog/archive/2011/04/22/2024878.html

相关资源:数据结构—成绩单生成器

最新回复(0)