Пример #1
0
        private static void GetBitmapSource(AnimatedGif gif, Bitmap bmap)
        {
            var handle = IntPtr.Zero;

            try
            {
                handle           = bmap.GetHbitmap();
                gif.BitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
                    handle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
            }
            finally
            {
                if (handle != IntPtr.Zero)
                {
                    DeleteObject(handle);
                }
            }
        }
Пример #2
0
        private static void BindSource(AnimatedGif gif)
        {
            gif.StopAnimate();
            gif.Bitmap?.Dispose();
            var path = gif.GifSource;

            if (string.IsNullOrWhiteSpace(path))
            {
                return;
            }
            if (!Path.IsPathRooted(path))
            {
                path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
            }
            if (!File.Exists(path))
            {
                return;
            }
            gif.Bitmap = new Bitmap(path);
            GetBitmapSource(gif, gif.Bitmap);
            gif.StartAnimate();
        }