Windows Phone没有完全截屏

时间:2014-01-06 10:35:19

标签: c# windows-phone-8

我在WP8中有一项任务

我需要在WP8屏幕中用户点击(按钮左右?)时截取屏幕并发送到某个服务器

我发送成功但问题有时候并不是将整个屏幕发送到我的服务器

这是我的代码:

private void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
    {
        TakeScreenShort();

    }  private void TakeScreenShort()
    {
        WriteableBitmap bmpCurrentScreenImage = new WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
        bmpCurrentScreenImage.Render(LayoutRoot, new MatrixTransform());
        bmpCurrentScreenImage.Invalidate();
        byte[] bytearray = null;
        using (MemoryStream ms = new MemoryStream())
        {
            WriteableBitmap wbitmp = new WriteableBitmap(bmpCurrentScreenImage);
            wbitmp.SaveJpeg(ms, wbitmp.PixelWidth, wbitmp.PixelHeight, 0, 100);
            ms.Seek(100, SeekOrigin.Current);
            bytearray = ms.GetBuffer();
        }
        string str = Convert.ToBase64String(bytearray);
        string json = JsonConvert.SerializeObject(new
        {
            id = 11544714,
            img = str,
            width = bmpCurrentScreenImage.PixelWidth,
            height = bmpCurrentScreenImage.PixelHeight,

        });

        string url = "http://178.188.9.96/imageservice/image.php";
        WebClient webClient = new WebClient();
        webClient.Headers["Content-Type"] = "application/json";
        webClient.Encoding = Encoding.UTF8;
        webClient.UploadStringCompleted += new UploadStringCompletedEventHandler(proxy_UploadStringCompleted);
        webClient.UploadStringAsync(new Uri(url), "POST", json, null);

    }

    private void proxy_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        var response = e.Result;
        var jsonData = JsonConvert.DeserializeObject<RootObject>(response);
    }

有时它会全屏显示,有时它不会占据整个屏幕。

1 个答案:

答案 0 :(得分:0)

实际上,您无法以编程方式获取屏幕截图。 奇怪的是,你已经设法使用它,你应该得到几个(3个左右)以确保全部。