[英]How to take a screenshot in WP8
所以我在WP8应用程序的PhoneApplicationPage中有一个DrawingSurfaceBackgroundGrid; 我想截图。 据我所知(来自Google),没有一个电话可以简单地“截取屏幕截图”。 人们正在使用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);
}
但是就像我说的,它只会产生黑色图像。
有任何想法吗?
在我的应用程序x:Name="LayoutRoot"
,将代码“ test”更改为根网格的名称,按原样尝试了代码,并且可以正常工作! 只需将test替换为要捕获的元素,整个页面的根网格名称或该元素的子元素名称即可。
顺便说一句,感谢您的代码,再松鼠了。
我正在使用下面的代码。 虽然它保存到媒体库。
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.