如何编程捕捉屏幕的Windows Phone 8.1 SDK? [英] How to capture screen programatically in windows phone 8.1 SDK?

查看:187
本文介绍了如何编程捕捉屏幕的Windows Phone 8.1 SDK?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不知道如何从代码捕获屏幕在SDK 8.1的Windows Phone?对于Windows Phone的7.5我已经看到了代码,并试图使用,但是失败了。 (

Any Idea how to capture screen in SDK 8.1 windows phone from code? For windows phone 7.5 i have seen the code and tried to use, but it failed. :(

推荐答案

您可以使用 RenderTargetBitmap 并传递给它一个FrameworkElement的。表示页,然后呈现从一个位图

You can use a RenderTargetBitmap and pass it a FrameworkElement that represents the page and then render a bitmap from that.

private async Task<RenderTargetBitmap> CreateBitmapFromElement(FrameworkElement uielement)
{
    try
    {
        var renderTargetBitmap = new RenderTargetBitmap();
        await renderTargetBitmap.RenderAsync(uielement);

        return renderTargetBitmap;
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine(ex);
    }

    return null;
}

尝试这样的:

private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
    this.imagePreview.Source = await CreateBitmapFromElement(this);
}

在您的页面上的XAML是:

where the XAML on your page is:

<Grid x:Name="controlsGrid">
    <Button Click="ButtonBase_OnClick">take screenshot</Button>
    <Image x:Name="imagePreview"
           Height="200" VerticalAlignment="Bottom"
           Stretch="UniformToFill" />
</Grid>

这篇关于如何编程捕捉屏幕的Windows Phone 8.1 SDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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