导入以下命名空间:

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 }

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

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

相关文章:

  • 2021-12-10
  • 2021-11-07
  • 2021-12-04
  • 2021-11-12
  • 2021-10-09
  • 2021-10-19
  • 2021-10-26
  • 2021-10-28
猜你喜欢
  • 2021-11-06
  • 2021-12-02
  • 2021-11-11
  • 2021-11-11
  • 2021-11-11
  • 2021-11-11
  • 2021-11-11
相关资源
相似解决方案