简体   繁体   English

如何在WP8中截屏

[英]How to take a screenshot in WP8

So I have a DrawingSurfaceBackgroundGrid inside of a PhoneApplicationPage, in my WP8 app; 所以我在WP8应用程序的PhoneApplicationPage中有一个DrawingSurfaceBackgroundGrid; and I would like to take a screenshot. 我想截图。 As far as I can tell (from google), there isn't a call to simply "take a screenshot". 据我所知(来自Google),没有一个电话可以简单地“截取屏幕截图”。 What people are doing is using a WriteableBitmap, like this: 人们正在使用WriteableBitmap,如下所示:

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

I have tried test as both the DrawingSurfaceBackgroundGrid, and the PhoneApplicationPage. 我已经尝试过同时作为DrawingSurfaceBackgroundGrid和PhoneApplicationPage进行测试。 Neither of these are working for me. 这些都不适合我。 Could it have something to do with the fact that I am rendering everything using RenderTargets and pixel shaders (in SharpDX)? 它是否与我使用RenderTargets和像素着色器(在SharpDX中)渲染所有东西有关? I just get a black image. 我刚得到一张黑色图像。 Here is the code to save the image: 这是保存图像的代码:

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);
}

But like I said, it just creates a black image. 但是就像我说的,它只会产生黑色图像。

Any ideas? 有任何想法吗?

Tried your code as is with the exception of changing "test" to the name of the root grid, in my app x:Name="LayoutRoot" , and works fine! 在我的应用程序x:Name="LayoutRoot" ,将代码“ test”更改为根网格的名称,按原样尝试了代码,并且可以正常工作! Just replace test with the element you want to capture, the root-grid name for whole page or sub element name for just that element. 只需将test替换为要捕获的元素,整个页面的根网格名称或该元素的子元素名称即可。


BTW thanks for the code, one more to squirrel away. 顺便说一句,感谢您的代码,再松鼠了。

I am using the code below. 我正在使用下面的代码。 Though it is saving to the Media Gallery. 虽然它保存到媒体库。

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM