Click here to Skip to main content
Click here to Skip to main content

GIF animation in WPF

, 14 Feb 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
Animation of a transparent GIF image in WPF.

Introduction

I have found a solution for GIF animation by only using Windows Forms. Based on this, I have solved this problem in WPF (.NET 3.5).

Using the Code

I have created my own class:

public class AnimatedImageControl : UserControl {...} 

and overridden the OnRender function:

protected override void OnRender(DrawingContext p_drawingContext)
{ 
   //Get the next frame ready for rendering.
   ImageAnimator.UpdateFrames(m_animatedImage);

   //Draw the next frame in the animation.
   Graphics gr = Graphics.FromHwnd(m_hwnd.Handle);
   gr.FillRectangle(m_brush, m_rectangle);
   gr.DrawImage(m_animatedImage, m_rectangle);
}

Points of Interest

The main trick is using Graphics instead of DrawingContext.

It works properly only if the background is a solid color brush, because calling FillRectangle() is necessary.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Zolador

Hungary Hungary
No Biography provided

Comments and Discussions

 
GeneralError in Code PinmemberRahul Singla16-Mar-09 8:00 
GeneralAn alternate solution PinmemberRob Reiss27-Feb-08 8:59 
GeneralRe: An alternate solution Pinmemberreinux23-Aug-08 23:40 
GeneralRe: An alternate solution PinmemberJeremyAC23-Sep-09 5:02 
GeneralAnother (better) solution PinmemberZoltan2315-Feb-08 2:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141216.1 | Last Updated 14 Feb 2008
Article Copyright 2008 by Zolador
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid