asp.net WPF uses Gifbitmapdecoder to parse GIF animated files

Source: Internet
Author: User
Thanks to the powerful encapsulation of WPF, all this is done with 3 pieces of code.
For example, we often see the rabbit rubbing the face of GIF:
Program Run Result:
The code uses the Bitmapdecoder type, and for the GIF animation, you need to initialize its subclass Gifbitmapdecoder. The Bitmapdecoder frames attribute contains a series of bitmapframe. This type is the image frame used in Bitmapdecoder (and Bitmapencoder) and inherits from BitmapSource, so it is essentially a bitmap type.
Xaml:
<listbox name= "LBX" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<image source= "{Binding}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Code:
            var uri = new Uri (@ "C:usersmgendesktop A.gif ");
            var gifdecoder = new Gifbitmapdecoder (URI, Bitmapcreateoptions.none, Bitmapcacheoption.default);
            LBX. ItemsSource = Gifdecoder.frames;
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.