Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

如何在Windows Phone 7上用编程方式截屏

From Wiki
Jump to: navigation, search
WP Metro Icon Multimedia.png
SignpostIcon XAML 40.png
SignpostIcon WP7 70px.png
Article Metadata

最后由 hamishwillee 在 17 Jul 2013 编辑

这篇文章解释了在Windows Phone 7如何利用managed API来截取当前手机屏幕。


最近Pavan收到一份mail询问有关如何在Windows Phone 7上捕获屏幕程序指令,所以他决定写一篇有关此的文章,希望能够对开发人员有所帮助。 WpScreen.png

为了截取屏幕利用WriteableBitmapMatrixTransform API,它们都是Managed API。MatrixTransform允许你创建一个任意的affine变换矩阵,用来操作一个二维平面坐标系。 这是代码片段。

private void ApplicationBarIconButton_Click(object sender, EventArgs e)
var fileName = String.Format("WmDev_{0:}.jpg", DateTime.Now.Ticks);
WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
bmpCurrentScreenImage.Render(LayoutRoot, new MatrixTransform());
SaveToMediaLibrary(bmpCurrentScreenImage, fileName, 100);
MessageBox.Show("Captured image " + fileName + " Saved Sucessfully", "WmDev Capture Screen", MessageBoxButton.OK);
currentFileName = fileName;
public void SaveToMediaLibrary(WriteableBitmap bitmap, string name, int quality)
using (var stream = new MemoryStream())
// Save the picture to the Windows Phone media library.
bitmap.SaveJpeg(stream, bitmap.PixelWidth, bitmap.PixelHeight, 0, quality);
stream.Seek(0, SeekOrigin.Begin);
new MediaLibrary().SavePicture(name, stream);

在代码片段中,创建一个具有特定长度和高度的WriteableBitmap类实例,它的对象的Render方法绘制一个屏幕上的元素至,它拥有两个参数UIElement 和Transform。UIElement参数用来指出要绘制的元素,Transform参数用来在绘制成位图前的变换。 将WriteableBitmap要求的所有UIElements获得后,我们需要Invalidate()方法来强制它重绘其内容并正确显示。 现在用SaveToMediaLibrary()方法将捕获的图像存储在媒体库中,它需要三个参数WriteableBitmapObject , filename, 和JPEG图像的质量。


我们使用了MatrixTransform 类,WriteableBitmap 类,MediaLibrary 类。

This page was last modified on 17 July 2013, at 05:05.
66 page views in the last 30 days.