如何在WP8中截取屏幕截图

时间:2013-01-30 18:57:51

标签: c# windows-phone-8

所以我在WP8应用程序中的PhoneApplicationPage中有一个DrawingSurfaceBackgroundGrid;我想截取屏幕截图。据我所知(来自谷歌),没有一个简单的“截取屏幕”的电话。人们正在做的是使用WriteableBitmap,如下所示:

WriteableBitmap wbmp = new WriteableBitmap(test, null);
wbmp.SaveJpeg(isoStream2, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);

我已经尝试过测试DrawingSurfaceBackgroundGrid和PhoneApplicationPage。这些都不适合我。它是否与我使用RenderTargets和像素着色器(在SharpDX中)渲染所有内容这一事实有关?我只是得到一个黑色的图像。以下是保存图像的代码:

IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication();

using (IsolatedStorageFileStream isoStream2 = new IsolatedStorageFileStream("new.jpg", FileMode.OpenOrCreate, isoStore))
{
    WriteableBitmap wbmp = new WriteableBitmap(test, null);
    wbmp.SaveJpeg(isoStream2, wbmp.PixelWidth, wbmp.PixelHeight, 0, 100);
}

但就像我说的那样,它只是创造了一个黑色的图像。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

在我的应用x:Name="LayoutRoot"中将“test”更改为根网格的名称除外,我们按原样尝试您的代码,并且工作正常!只需将 test 替换为您要捕获的元素,整个页面的根网格名称或仅该元素的子元素名称。


顺便说一句,感谢您的代码,还有一个要松散的。

答案 1 :(得分:0)

我正在使用以下代码。虽然它正在保存到媒体库。

WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
bmpCurrentScreenImage.Render(LayoutRoot, new MatrixTransform());
bmpCurrentScreenImage.Invalidate();
using (var stream = new MemoryStream())
{
    // Save the picture to the Windows Phone media library.
    bmpCurrentScreenImage.SaveJpeg(stream, bmpCurrentScreenImage.PixelWidth, bmpCurrentScreenImage.PixelHeight, 0, quality);
    stream.Seek(0, SeekOrigin.Begin);

    var picture = new MediaLibrary().SavePicture(name, stream);
    return picture.GetPath();
}
相关问题