CapturePreviewToStreamAsync method
TOC
Collapse the table of content
Expand the table of content

WebView.CapturePreviewToStreamAsync method

Creates an image of the current WebView contents and writes it to the specified stream.

Syntax


public:
IAsyncAction^ CapturePreviewToStreamAsync(
  IRandomAccessStream^ stream
)

Parameters

stream

Type: IRandomAccessStream

The stream to write the image to.

Return value

Type: IAsyncAction

An asynchronous action to await the capture operation.

Examples

This example shows how to use this method to create a thumbnail image of the current content. For the complete example, see the WebView control sample.


private async void bookmarkBtn_Click(object sender, RoutedEventArgs e)
{
    InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream();
    await webView8.CapturePreviewToStreamAsync(ms);
            
    // Create a small thumbnail.
    int longlength = 180, width = 0, height = 0;
    double srcwidth = webView8.ActualWidth, srcheight = webView8.ActualHeight;
    double factor = srcwidth / srcheight;
    if (factor < 1)
    {
        height = longlength;
        width = (int)(longlength * factor);
    }
    else
    {
        width = longlength;
        height = (int)(longlength / factor);
    }
    BitmapSource small = await resize(width, height, ms);
            
    BookmarkItem item = new BookmarkItem();
    item.Title = webView8.DocumentTitle;
    item.PageUrl = webView8.Source;
    item.Preview = small;

    bookmarks.Add(item);
}


Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Controls
Windows::UI::Xaml::Controls [C++]

Metadata

Windows.winmd

See also

WebView
XAML WebView control sample
WebView control (XAML) sample (Windows 10)

 

 

Show:
© 2016 Microsoft