如何在Windows手机上编程截取屏幕?

5

我想用 Windows Phone 拍摄屏幕截图。 我不想使用模拟器和 power+start 按钮手动拍摄屏幕截图。 有没有什么可以通过编程实现的方法?

1个回答

8

以下是代码:

private void ApplicationBarScreenshotButton_Click(object sender, EventArgs e)
{
    var fileName = String.Format("MyImage_{0:}.jpg", DateTime.Now.Ticks);
    WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
    bmpCurrentScreenImage.Render(LayoutRoot, new MatrixTransform());
    bmpCurrentScreenImage.Invalidate();
    SaveToMediaLibrary(bmpCurrentScreenImage, fileName, 100);
    MessageBox.Show("Captured image " + fileName + " Saved Sucessfully", "WP 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);
    }
}

当您点击AppBar按钮时,它将拍下屏幕截图,并保存该图片到Windows Phone媒体库中。

很好,它正在正常工作。当某个消息框或键盘弹出时,我想通过编程方式截取屏幕截图,这是否可行? - Satti
谢谢,即使是虚拟键盘弹出,您也可以通过点击ApplicationBarIconButton执行相同的操作来截屏。但是,如果您想在任何MessageBox弹出时进行截屏,则需要同时按下Windows Home和Power按钮。我没有尝试过其他替代方法。 - Rashad Valliyengal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接