New Windows 8.1 Controls and features:

Source: Internet
Author: User

To render a XAML tree as a bitmap:

The Windows Runtime for Windows 8.1 adds a new type for the Windows.UI.Xaml.Media.Imaging namespace:rendertargetbitmap.

This type provides two key methods:

    • Rendertargetbitmap.renderasync, which is used to extract the XAML visual tree and create a bitmap representation for it.

      Note This operation asynchronously renders the given XAML element tree as a bitmap. This method is not synchronized with the screen refresh and does not guarantee precise frame timing, so the bitmap may be rendered at a moment before and after the assumed capture time.

    • A Rendertargetbitmap.getpixelsasyncthat is used to return a byte array of pixels in a particular format.

The following example shows how to render a XAML element tree.

var New RenderTargetBitmap (); await  = RenderTargetBitmap;

RenderTargetBitmap inherits from ImageSource, so it can be set directly as the source of an Image object without calling Getpixelsasync To get and display the bitmap data.

The following example shows how to write a rendered bitmap to a file.

            varBitmap =NewRenderTargetBitmap (); awaitBitmap. Renderasync ( This.            C1); IBuffer Buffer=awaitbitmap.            Getpixelsasync (); varPixelstream =buffer.            Asstream (); Filesavepicker Savepicker=NewFilesavepicker (); Savepicker.suggestedstartlocation=Pickerlocationid.desktop; SAVEPICKER.FILETYPECHOICES.ADD ("Bitmap",Newlist<string> () {". PNG" }); Savepicker.suggestedfilename="New Bitmap"; StorageFile Saveditem=awaitSavepicker.picksavefileasync (); Guid Encoderid=Bitmapencoder.pngencoderid; Irandomaccessstream FileStream=awaitSaveditem.openasync (Windows.Storage.FileAccessMode.ReadWrite); Bitmapencoder Encoder=awaitBitmapencoder.createasync (Encoderid, FileStream); byte[] pixels =New byte[Pixelstream.length]; Pixelstream.read (Pixels,0, pixels.            Length); //pixal format Shouldconvert to Rgba8             for(inti =0; I < pixels. Length; i + =4)            {                bytetemp =Pixels[i]; Pixels[i]= Pixels[i +2]; Pixels[i+2] =temp; } encoder. Setpixeldata (Bitmappixelformat.rgba8, Bitmapalphamode.straight, (UINT) bitmap. Pixelwidth, (UINT) bitmap. Pixelheight, the,//Horizontal DPI              the,//Vertical DPIpixels); awaitEncoder. Flushasync ();

Metroapp save Uiement The same code as the picture http://www.cnblogs.com/manupstairs/p/3556642.html. its//Pixal format shouldconvert to Rgba8 The following section of the Exchange code does not change color.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.