In GIF-Grafikdateien lassen sich mehrere Grafiken verbinden und für Animationen aufbereiten. Das Bildfeld PictureBox unterstützt zwar das GIF-Grafikdateiformat, spielt aber die in GIF-Dateien enthaltenen Animationen nicht ab. Kann man das ändern und wenn ja wie? Oder muss ich auf ein kommerzielles Steuerelement zurückgreifen? Im Internet habe ich entsprechende COM-Komponenten gefunden. Ich möchte in jedem Fall eine .NET-Lösung verwenden.
ich nehme an es handelt sich um ein WPF Problem, denn dort kann die PictureBox Animated GIFs nicht darstellen. Eine Möglichkeit wäre die Windows Forms PictureBox zu verwenden:
public class AnimatedImage : System.Windows.Controls.Image { private List<BitmapSource> _BitmapSources = null; private int _nCurrentFrame = 0; private List<int> Delays = null; private Timer timer = null;
private bool _bIsAnimating = false;
public bool IsAnimating { get { return _bIsAnimating; } }
static AnimatedImage() { DefaultStyleKeyProperty.OverrideMetadata(typeof(AnimatedImage), new FrameworkPropertyMetadata(typeof(AnimatedImage))); }
/// <summary> /// Animated GIF image. /// </summary> public Bitmap AnimatedBitmap { get { return (Bitmap)GetValue(AnimatedBitmapProperty); } set { StopAnimate(); SetValue(AnimatedBitmapProperty, value); } }
public static readonly DependencyProperty AnimatedBitmapProperty = DependencyProperty.Register( "AnimatedBitmap", typeof(Bitmap), typeof(AnimatedImage), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnAnimatedBitmapChanged)));
RoutedPropertyChangedEventArgs<Bitmap> e = new RoutedPropertyChangedEventArgs<Bitmap>( (Bitmap)args.OldValue, (Bitmap)args.NewValue, AnimatedBitmapChangedEvent); control.OnAnimatedBitmapChanged(e); }
using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Runtime.InteropServices; using System.Threading; using System.Windows; using System.Windows.Media.Imaging; using System.Windows.Threading;