Jayakrishnan
Jayakrishnan

Reputation: 4294

RenderTargetBitmap is not capturing WebView Content in Windows phone 8.1 WinRT App

I am trying to take screenshot of Webview Control using below code:

async Task<RenderTargetBitmap> CaptureToStreamAsync(FrameworkElement uielement, IRandomAccessStream stream, Guid encoderId)
  {
      try
      {
          var renderTargetBitmap = new RenderTargetBitmap();
          await renderTargetBitmap.RenderAsync(uielement);
          var pixels = await renderTargetBitmap.GetPixelsAsync();
          var logicalDpi = DisplayInformation.GetForCurrentView().LogicalDpi;
          var encoder = await BitmapEncoder.CreateAsync(encoderId, stream);
          encoder.SetPixelData(
              BitmapPixelFormat.Bgra8,
              BitmapAlphaMode.Ignore,
              (uint)renderTargetBitmap.PixelWidth,
              (uint)renderTargetBitmap.PixelHeight,
              logicalDpi,
              logicalDpi,
              pixels.ToArray());

          await encoder.FlushAsync();
          return renderTargetBitmap;

      }
      catch (Exception ex)
      {
          DisplayMessage(ex.Message);
      }

      return null;
  }

RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(RenderedGrid);
RenderedImage.Source = renderTargetBitmap;

But I am getting blank image. It works fine for all other controls. Please help!

Upvotes: 1

Views: 627

Answers (2)

Vitor Antonio
Vitor Antonio

Reputation: 134

It is not possible to capture using RenderTargetBitmap but you can use: CapturePreviewToStreamAsync

WebView.CapturePreviewToStreamAsync method

Also take a look a the sample for WebView:

XAML WebView control sample

Upvotes: 2

Jayakrishnan
Jayakrishnan

Reputation: 4294

It's not possible to capture screenshot of Webview on Windows phone. Please see below link:

Limitation of RenderTargetBitmap

Upvotes: 1

Related Questions