我想用 Windows Phone 拍摄屏幕截图。 我不想使用模拟器和 power+start 按钮手动拍摄屏幕截图。 有没有什么可以通过编程实现的方法?
我想用 Windows Phone 拍摄屏幕截图。 我不想使用模拟器和 power+start 按钮手动拍摄屏幕截图。 有没有什么可以通过编程实现的方法?
以下是代码:
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);
}
}