如何在 WP8 中截取屏幕截图 [英] How to take a screenshot in WP8

查看:18
本文介绍了如何在 WP8 中截取屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I have a DrawingSurfaceBackgroundGrid inside of a PhoneApplicationPage, in my WP8 app; 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". What people are doing is using a WriteableBitmap, like this:

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

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

I have tried test as both the DrawingSurfaceBackgroundGrid, and the 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)? 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.

有什么想法吗?

推荐答案

我正在使用下面的代码.虽然它正在保存到媒体库.

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

这篇关于如何在 WP8 中截取屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆