WP7:从应用程序中截取屏幕截图

如何从代码中截取屏幕截图?

检查一下 ,它似乎可能在模拟器上。

使用WriteableBitmap从应用程序代码中截取应用程序的截图非常简单。 Laurent Bugnion在这里写得很好: http : //geekswithblogs.net/lbugnion/archive/2010/12/28/taking-a-screenshot-from-within-a-silverlight-wp7-application.aspx

从Silverlight#WP7应用程序中截取屏幕截图。

 public static void SaveToMediaLibrary( FrameworkElement element, string title) { try { var bmp = new WriteableBitmap(element, null); var ms = new MemoryStream(); bmp.SaveJpeg( ms, (int)element.ActualWidth, (int)element.ActualHeight, 0, 100); ms.Seek(0, SeekOrigin.Begin); var lib = new MediaLibrary(); var filePath = string.Format(title + ".jpg"); lib.SavePicture(filePath, ms); MessageBox.Show( "Saved in your media library!", "Done", MessageBoxButton.OK); } catch { MessageBox.Show( "There was an error. Please disconnect your phone from the computer before saving.", "Cannot save", MessageBoxButton.OK); }} 

以下是如何从您的应用中截取您的页面代码中的屏幕截图并将其保存到手机的图片库中。 请注意,这不会捕获SysTray或AppBar:

 WriteableBitmap w = new System.Windows.Media.Imaging.WriteableBitmap(this, null); // 'this' is your current page WriteableBitmap w2 = new System.Windows.Media.Imaging.WriteableBitmap(480, 800); // space for SysTray for (int i = 0; i < 32; i++) { for (int j = 0; j < 480; j++) { w2.Pixels[i * 480 + j] = -16777216; // black #ff000000 } } // actual client area for (int i = 32; i < 728; i++) { for (int j = 0; j < 480; j++) { w2.Pixels[i * 480 + j] = w.Pixels[(i - 32) * 480 + j]; } } // space for AppBar for (int i = 728; i < 800; i++) { for (int j = 0; j < 480; j++) { w2.Pixels[i * 480 + j] = -16777216; // black #ff000000 } } MemoryStream ms = new MemoryStream(); w2.SaveJpeg(ms, 480, 800, 0, 100); Microsoft.Xna.Framework.Media.MediaLibrary lib = new Microsoft.Xna.Framework.Media.MediaLibrary(); ms.Position = 0; lib.SavePicture("screenshot", ms); 

你不能害怕。 如果你想要截图,你需要在外面使用像剪切工具这样的东西。