public void GetGifPalette(Bitmap bit) { using (MemoryStream imageStreamSource = new MemoryStream()) { System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter(); byte[] btImage = (byte[])ic.ConvertTo(bit, typeof(byte[])); imageStreamSource.Write(btImage, 0, btImage.Length); GifBitmapDecoder decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapPalette pal = decoder.Palette; int i; for (i = 0; i < 0x100; i++) { this.Palette[i] = 0; } try { i = 0; while (i < 0x100) //&& i < pal.Colors.Count) { int Red = pal.Colors[i].R / 8; int Green = pal.Colors[i].G / 8; int Blue = pal.Colors[i].B / 8; int contaFinal = (((0x400 * Red) + (0x20 * Green)) + Blue) + 0x8000; if (contaFinal == 0x8000) { contaFinal = 0x8001; } this.Palette[i] = (ushort)contaFinal; i++; } } catch (System.IndexOutOfRangeException) { } catch (System.ArgumentOutOfRangeException) { } for (i = 0; i < 0x100; i++) { if (this.Palette[i] < 0x8000) { this.Palette[i] = 0x8000; } } } }
public BombSource(int ID) { XElement config = XElement.Load(@"Source\BombSource\BombConfig.xml"); XElement BombDate = Source.GetTreeNode(config, "Bomb", "Sign", ID + ""); temp = BombDate.Element("bomb"); decoder = new GifBitmapDecoder(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative) , BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); for (int i = 0; i < decoder.Frames.Count; i++) { bomb.Add(decoder.Frames[i]); } temp = BombDate.Element("effect"); effect = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = BombDate.Element("skill1"); skill1 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = BombDate.Element("skill2"); skill2 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = BombDate.Element("skill3"); skill3 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = BombDate.Element("skill4"); skill4 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = BombDate.Element("skill5"); skill5 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = BombDate.Element("skill6"); skill6 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = BombDate.Element("skill7"); skill7 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); }
public static BitmapFrame Open(string fileName) { if (File.Exists(fileName)) { using (var fStream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { string ext = Path.GetExtension(fileName); if (ext == ".gif") { var decoder = new GifBitmapDecoder(fStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); return(decoder.Frames.FirstOrDefault()); } if (ext == ".bmp") { var decoder = BitmapDecoder.Create(fStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); return(decoder.Frames.FirstOrDefault()); } if (ext == ".png") //Because why not? { var decoder = new PngBitmapDecoder(fStream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad); return(decoder.Frames.FirstOrDefault()); } } } else { //Log.Warning($"Texture file {fileName} not found."); } return(null); }
public void CreateGifAnimation(MemoryStream memoryStream) { Reset(); //memoryStream.GetBuffer()返回从其创建此流的无符号字节数组。 byte[] gifData = memoryStream.GetBuffer(); // Use GetBuffer so that there is no memory copy //将动态GIF分解成很多帧并保存在一个列表中,每一帧为一个BitmapFrame类型的对象,其父类为BitmapSource,这也就意味着,我们可以将每一帧赋值给一个Image控件的Source属性, //使用GifBitmapDecoder解析GIF动画文件 // bitmapUri // Uri ,它标识要解码的位图。 //createOptions // 位图图像的初始化选项。 //cacheOption // 用于位图图像的缓存方法。 //从指定的 Uri 中,用指定的 createOptions 和 cacheOption 初始化 GifBitmapDecoder 的一个新实例 GifBitmapDecoder decoder = new GifBitmapDecoder(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); //decoder.Frames获取位图中单个帧的内容。 numberOfFrames = decoder.Frames.Count; try { ParseGif(gifData); } catch { throw new FileFormatException("Unable to parse Gif file format."); } for (int i = 0; i < decoder.Frames.Count; i++) { frameList[i].Source = decoder.Frames[i]; frameList[i].Visibility = Visibility.Hidden; canvas.Children.Add(frameList[i]); Canvas.SetLeft(frameList[i], frameList[i].left); Canvas.SetTop(frameList[i], frameList[i].top); Canvas.SetZIndex(frameList[i], i); } canvas.Height = logicalHeight; canvas.Width = logicalWidth; frameList[0].Visibility = Visibility.Visible; for (int i = 0; i < frameList.Count; i++) { Console.WriteLine(frameList[i].disposalMethod.ToString() + " " + frameList[i].width.ToString() + " " + frameList[i].delayTime.ToString()); } if (frameList.Count > 1) { if (numberOfLoops == -1) { numberOfLoops = 1; } frameTimer = new System.Windows.Threading.DispatcherTimer(); frameTimer.Tick += NextFrame; frameTimer.Interval = new TimeSpan(0, 0, 0, 0, frameList[0].delayTime * 10); frameTimer.Start(); } }
private void Initialize() { _gifDecoder = new GifBitmapDecoder(GifSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); var keyFrames = new Int32KeyFrameCollection(); TimeSpan last = TimeSpan.Zero; for (int i = 0; i < _gifDecoder.Frames.Count; i++) { var gifDecoderFrame = _gifDecoder.Frames[i]; var bitmapMetadata = gifDecoderFrame.Metadata as BitmapMetadata; var delayTime = bitmapMetadata?.GetQuery("/grctlext/Delay") as ushort?; var delay = delayTime ?? 10; if (delay == 0) { delay = 10; } last += TimeSpan.FromMilliseconds(delay * 10); keyFrames.Add(new DiscreteInt32KeyFrame(i, KeyTime.FromTimeSpan(last))); } _animation = new Int32AnimationUsingKeyFrames() { KeyFrames = keyFrames, RepeatBehavior = RepeatBehavior.Forever, }; _isInitialized = true; }
//Load grid and return as 2d Grids public static GridList GifToGrids(string filename) { #if !NET2 GridList grids = new GridList(); // Open a Stream and decode a GIF image Stream imageStreamSource = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read); var decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); decoder.Frames[0].Metadata.Freeze(); int width = GetMaxX(decoder); int height = GetMaxY(decoder); foreach (BitmapFrame frame in decoder.Frames) { frame.Freeze(); // Get a clone copy of the metadata var sourceMetadata = frame.Metadata as BitmapMetadata; int top = Int32.Parse(sourceMetadata.GetQuery("/imgdesc/Top").ToString()); int left = Int32.Parse(sourceMetadata.GetQuery("/imgdesc/Left").ToString()); Grid grid = new Grid(width, height, 1, 4); CopyBitmapSourceToGridPalette(frame, grid, top, left); grids.AddGrid(grid); } return(grids); #else return(null); #endif }
public PreviewGif(Stream gifStream) { InitializeComponent(); gifStream.Seek(0, SeekOrigin.Begin); var decoder = GifBitmapDecoder.Create(gifStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); var frameIdx = 0; var dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += delegate { Dispatcher.BeginInvoke(new Action(delegate { imgFrameHolder.Source = decoder.Frames[frameIdx]; frameIdx++; if (frameIdx == decoder.Frames.Count) { frameIdx = 0; } })); }; dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 500); dispatcherTimer.Start(); }
private void GifImage_Initialized(object sender, EventArgs e) { gifDecoder = new GifBitmapDecoder(Uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); animation = new Int32Animation(0, gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, gifDecoder.Frames.Count / 10, (int)((gifDecoder.Frames.Count / 10.0 - gifDecoder.Frames.Count / 10) * 1000)))); animation.RepeatBehavior = RepeatBehavior.Forever; Source = gifDecoder.Frames[0]; }
public MenuScreen() { InitializeComponent(); Uri myUri = new Uri(@"..\..\img\pika.gif", UriKind.RelativeOrAbsolute); GifBitmapDecoder decoder2 = new GifBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmapSource2; int frameCount = decoder2.Frames.Count; try { Thread th = new Thread(() => { while (true) { for (int i = 0; i < frameCount; i++) { this.Dispatcher.Invoke(new Action(delegate() { bitmapSource2 = decoder2.Frames[i]; homeGif.Source = bitmapSource2; })); System.Threading.Thread.Sleep(100); } } }); th.Start(); } catch (Exception ex) { Console.WriteLine("Exception thown in gif thread ERROR: ", ex.Message); } }
internal static BitmapSource ToImageSource(string ext, Stream s) { ext = ext.ToLower(); if (ext.EndsWith(".png")) { var bitmapDecoder = new PngBitmapDecoder(s, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); return(bitmapDecoder.Frames[0]); } if (ext.EndsWith(".gif")) { var bitmapDecoder = new GifBitmapDecoder(s, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); return(bitmapDecoder.Frames[0]); } if (ext.EndsWith(".jpg")) { var bitmapDecoder = new JpegBitmapDecoder(s, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None); return(bitmapDecoder.Frames[0]); } // http://stackoverflow.com/questions/2835502/rotating-cursor-according-to-rotated-textbox // http://stackoverflow.com/questions/46805/custom-cursor-in-wpf // http://stackoverflow.com/questions/2284353/is-there-a-good-way-to-convert-between-bitmapsource-and-bitmap // http://www.gdgsoft.com/anituner/help/aniformat.htm // http://msdn.microsoft.com/en-us/library/ms608877.aspx throw new NotSupportedException(ext); }
/// <summary> /// Initializes a new instance of the <see cref="AnimatedLoader" /> class. /// </summary> public AnimatedLoader() { Visibility = Visibility.Hidden; IsVisibleChanged += LoaderVisibilityChanged; var imageSource = Application.Current.Resources["LoaderImage"] as ImageSource; var loaderUri = imageSource == null ? new Uri("pack://application:,,,/Nova;component/Resources/loader.gif", UriKind.Absolute) : new Uri(imageSource.ToString(), UriKind.Absolute); _gifBitmapDecoder = new GifBitmapDecoder(loaderUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); var seconds = _gifBitmapDecoder.Frames.Count / 10; var milliseconds = (int)(((_gifBitmapDecoder.Frames.Count / 10.0) - (_gifBitmapDecoder.Frames.Count / 10.0)) * 1000d); var timespan = new TimeSpan(0, 0, 0, seconds, milliseconds); var duration = new Duration(timespan); _animation = new Int32Animation(0, _gifBitmapDecoder.Frames.Count - 1, duration) { RepeatBehavior = RepeatBehavior.Forever }; Source = _gifBitmapDecoder.Frames[0]; Height = Source.Height; Width = Source.Width; }
public RibbonGifControl(String path, RibbonRadioButton im) { if (null == im) { throw new Exception("Error: null Image"); } m_bitmapSources = new List <BitmapSource>(); m_ribbonButton = im; m_imageStreamSource = new FileStream(@path, FileMode.Open, FileAccess.Read, FileShare.Read); m_decoder = new GifBitmapDecoder(m_imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); for (int i = 0; i < m_decoder.Frames.Count; i++) { m_bitmapSources.Add(m_decoder.Frames[i]); } if (m_decoder.Frames.Count < 1) { throw new Exception("Error gif with no frames: " + path); } m_index = m_decoder.Frames.Count - 1; m_ribbonButton.SmallImageSource = m_bitmapSources[m_index]; //image.Width = bitmapSources[index].Width; //image.Height = bitmapSources[index].Height; m_dispatcherTimer = new DispatcherTimer(); m_dispatcherTimer.Interval = TimeSpan.FromMilliseconds(300); m_dispatcherTimer.Tick += delegate { flip(); }; }
public RadioGifControl(String path, RadioButton but) { if (null == but) { throw new Exception("Error: null button"); } bitmapSources = new List <BitmapSource>(); button = but; imageStreamSource = new FileStream(@path, FileMode.Open, FileAccess.Read, FileShare.Read); decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); for (int i = 0; i < decoder.Frames.Count; i++) { bitmapSources.Add(decoder.Frames[i]); } if (decoder.Frames.Count < 1) { throw new Exception("Error gif with no frames: " + path); } index = decoder.Frames.Count - 1; image = new Image(); image.SnapsToDevicePixels = true; image.UseLayoutRounding = true; image.Source = bitmapSources[index]; but.Content = image; //image.Width = bitmapSources[index].Width; //image.Height = bitmapSources[index].Height; dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Interval = TimeSpan.FromMilliseconds(300); dispatcherTimer.Tick += delegate { flip(); }; //dispatcherTimer.Start(); }
private void InitFromUri(Uri uri) { if (uri == null) { _gifDecoder = null; _animation = null; _animationIsWorking = false; return; } var decoder = BitmapDecoder.Create(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _gifDecoder = decoder as GifBitmapDecoder; if (_gifDecoder != null) { _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))) { RepeatBehavior = RepeatBehavior.Forever }; } else { _animation = null; _animationIsWorking = false; } Source = decoder.Frames[0]; }
/// <summary> /// Initializes this instance. /// </summary> private void Initialize() { if (string.IsNullOrEmpty(this.GifSource)) { // this.GifSource = "/LoadTariffs;component/Resources/Images/Windows8loader.gif"; this.GifSource = "/Umehluko.Tools.UI;component/Resources/Images/Windows8loader.gif"; } this._gifDecoder = new GifBitmapDecoder( new Uri("pack://application:,,," + this.GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); this._animation = new Int32Animation( 0, this._gifDecoder.Frames.Count - 1, new Duration( new TimeSpan( 0, 0, 0, this._gifDecoder.Frames.Count / 10, (int)((this._gifDecoder.Frames.Count / 10.0 - this._gifDecoder.Frames.Count / 10) * 1000)))) { RepeatBehavior = RepeatBehavior .Forever }; this.Source = this._gifDecoder.Frames[0]; this._isInitialized = true; }
public static BitmapSource GifToLongBmp(string LoadFilePath) { // GifBitmapDecoder gifDecoder = new GifBitmapDecoder(new Uri(LoadFilePath, UriKind.Relative), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); //MessageBox.Show(string.Format("{0}", gifDecoder.Frames.Count)); // //берем размер кадра BitmapFrame frame0 = gifDecoder.Frames[0]; int imageWidth = frame0.PixelWidth; int imageHeight = frame0.PixelHeight; int frameCount = gifDecoder.Frames.Count; // компонент для отрисовки всех кадров DrawingVisual drawingVisual = new DrawingVisual(); using (DrawingContext drawingContext = drawingVisual.RenderOpen()) { for (int i = 0; i < gifDecoder.Frames.Count; i++) { BitmapFrame frame1 = gifDecoder.Frames[i]; drawingContext.DrawImage(frame1, new Rect(i * imageWidth, 0, imageWidth, imageHeight)); } } //конверт в BitmapSource RenderTargetBitmap bmp = new RenderTargetBitmap(imageWidth * frameCount, imageHeight, 96, 96, PixelFormats.Pbgra32); bmp.Render(drawingVisual); return(bmp); }
public MapSource(int ID) { XElement config = XElement.Load(@"Source\MapSource\MapConfig.xml"); XElement MapDate = Source.GetTreeNode(config, "Map", "Sign", ID + ""); temp = MapDate.Element("Background"); background_p = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("StartMask1"); start_p1 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("StartMask2"); start_p2 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("Brick"); brick_p = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("HPDrug"); HpDrug = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("MPDrug"); MpDrug = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("HMDrug"); HMDrug = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("Decoration1"); Decoration1 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("Decoration2"); Decoration2 = BitmapFrame.Create(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative)); temp = MapDate.Element("Effect"); var decoder = new GifBitmapDecoder(new Uri(string.Format(@"{0}", temp.Attribute("Src").Value), UriKind.Relative) , BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); for (int i = 0; i < decoder.Frames.Count; i++) { effect.Add(decoder.Frames[i]); } }
public void GetAnimator(ObjectAnimationUsingKeyFrames animator, string path) { var decoder = new GifBitmapDecoder(new Uri(path), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); var clock = TimeSpan.Zero; BitmapSource prevFrame = null; FrameInfo prevInfo = null; foreach (var rawFrame in decoder.Frames) { var info = GetFrameInfo(rawFrame); var frame = MakeFrame( decoder.Frames[0], rawFrame, info, prevFrame, prevInfo); prevFrame = frame; prevInfo = info; animator.KeyFrames.Add(new DiscreteObjectKeyFrame(frame, clock)); clock += info.Delay; } animator.Duration = clock; animator.RepeatBehavior = RepeatBehavior.Forever; }
public static BitmapDecoder CreateBitmapDecoder(BitmapEncodingMode mode, Stream fs, BitmapCreateOptions createOpt, BitmapCacheOption cacheOpt) { BitmapDecoder e = null; switch (mode) { case BitmapEncodingMode.Bmp: e = new BmpBitmapDecoder(fs, createOpt, cacheOpt); break; case BitmapEncodingMode.Gif: e = new GifBitmapDecoder(fs, createOpt, cacheOpt); break; case BitmapEncodingMode.Jpeg: e = new JpegBitmapDecoder(fs, BitmapCreateOptions.None, BitmapCacheOption.Default); break; case BitmapEncodingMode.Png: e = new PngBitmapDecoder(fs, createOpt, cacheOpt); break; case BitmapEncodingMode.Tiff: e = new TiffBitmapDecoder(fs, createOpt, cacheOpt); break; case BitmapEncodingMode.Wmp: e = new WmpBitmapDecoder(fs, createOpt, cacheOpt); break; } return(e); }
/// <summary> /// 根据 GIF 的元数据信息,计算出所有帧的图像,并获得每一帧的间隔(GIF的每一帧是相对于上一帧改变的像素,是压缩过的) /// </summary> /// <returns></returns> public (List <BitmapSource> BitmapSources, List <TimeSpan> TimeSpans) GetAllFrame() { List <BitmapSource> bitmapSources = new List <BitmapSource>(); List <TimeSpan> spans = new List <TimeSpan>(); if (!File.Exists(gifpath)) { return(bitmapSources, spans); } GifBitmapDecoder decoder = new GifBitmapDecoder(new Uri(gifpath), BitmapCreateOptions.None, BitmapCacheOption.OnLoad); if (decoder != null && decoder.Frames.Count > 0) { int index = 0; BitmapSource baseFrame = null; foreach (var rawFrame in decoder.Frames) { var metadata = GetFrameMetadata(decoder.Frames[index]); int width = decoder.Metadata.GetQueryOrDefault("/logscrdesc/Width", 0); int height = decoder.Metadata.GetQueryOrDefault("/logscrdesc/Height", 0); var frame = MakeFrame(width, height, rawFrame, metadata, baseFrame); baseFrame = frame; bitmapSources.Add(frame); spans.Add(metadata.Delay); index++; } } return(bitmapSources, spans); }
public GifImage(Uri uri) { gf = new GifBitmapDecoder(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); anim = new Int32Animation(0, gf.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, gf.Frames.Count / 12, (int)((gf.Frames.Count / 12.0 - gf.Frames.Count / 12) * 1000)))); anim.RepeatBehavior = RepeatBehavior.Forever; Source = gf.Frames[0]; }
private void Initialize() { gifDecoder = new GifBitmapDecoder(new Uri("pack://application:,,," + this.Source), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); this.animation = new Int32Animation(0, this.gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, this.gifDecoder.Frames.Count / 10, (int)((this.gifDecoder.Frames.Count / 10.0 - this.gifDecoder.Frames.Count / 10) * 1000)))); this.animation.RepeatBehavior = RepeatBehavior.Forever; base.Source = gifDecoder.Frames[0]; this.isInitialized = true; }
protected override void OnInitialized(EventArgs e) { gf = new GifBitmapDecoder(new Uri(Uri, UriKind.RelativeOrAbsolute), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); anim = new Int32Animation(0, gf.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, gf.Frames.Count / (int)fps, (int)((gf.Frames.Count / (double)fps - gf.Frames.Count / (int)fps) * 1000)))); anim.RepeatBehavior = RepeatBehavior.Forever; Source = gf.Frames[0]; }
public static IAnimation LoadAnimation(string filename, int?framerate = null) { var uri = new Uri(filename); var decoder = new GifBitmapDecoder(uri, BitmapCreateOptions.None, BitmapCacheOption.Default); var frames = decoder.Frames.Select(x => new WriteableBitmap(x).Scale(0.99)).ToArray();// todo: remove scaling - Why does scaling fix this bug??! return(new WpfAnimation(frames, framerate ?? 40)); }
public static BitmapSource[] OpenGIF(this BitmapSource source, Uri uri, BitmapCreateOptions create, BitmapCacheOption cache, out BitmapMetadata data) { BitmapDecoder dec = new GifBitmapDecoder(uri, create, cache); data = dec.Metadata; return(dec.Frames.ToArray()); }
private void Initialize() { _gifDecoder = FASTBuildMonitorControl.GetGifBitmapDecoder(GifSource); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }
private void Initialize() { _gifDecoder = new GifBitmapDecoder(new Uri(this.Source.ToString(Global.cultures)), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / 10, (int)((_gifDecoder.Frames.Count / 10.0 - _gifDecoder.Frames.Count / 10) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }
public void CreateGifAnimation(MemoryStream memoryStream) { try { Reset(); byte[] gifData = memoryStream.GetBuffer(); // Use GetBuffer so that there is no memory copy GifBitmapDecoder decoder = new GifBitmapDecoder(memoryStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _numberOfFrames = decoder.Frames.Count; try { ParseGif(gifData); } catch { throw new FileFormatException("Unable to parse Gif file format."); } for (int f = 0; f < decoder.Frames.Count; f++) { _frameList[f].Source = decoder.Frames[f]; _frameList[f].Visibility = Visibility.Hidden; _canvas.Children.Add(_frameList[f]); Canvas.SetLeft(_frameList[f], _frameList[f].left); Canvas.SetTop(_frameList[f], _frameList[f].top); Canvas.SetZIndex(_frameList[f], f); } _canvas.Height = _logicalHeight; _canvas.Width = _logicalWidth; _frameList[0].Visibility = Visibility.Visible; for (int i = 0; i < _frameList.Count; i++) { Console.WriteLine(_frameList[i].disposalMethod.ToString() + " " + _frameList[i].width.ToString() + " " + _frameList[i].delayTime.ToString()); } if (_frameList.Count > 1) { if (_numberOfLoops == -1) { _numberOfLoops = 1; } _frameTimer = new System.Windows.Threading.DispatcherTimer(); _frameTimer.Tick += NextFrame; _frameTimer.Interval = new TimeSpan(0, 0, 0, 0, _frameList[0].delayTime * 10); _frameTimer.Start(); } } catch (Exception ex) { VMuktiAPI.VMuktiHelper.ExceptionHandler(ex, "CreateGifAnimation()", "Controls\\VMuktiGrid\\GifAnimation.cs"); } }
private void Initialize() { _gifDecoder = new GifBitmapDecoder(new Uri("pack://application:,,," + this.GifSource), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); _animation = new Int32Animation(0, _gifDecoder.Frames.Count - 1, new Duration(new TimeSpan(0, 0, 0, _gifDecoder.Frames.Count / Time, (int)((_gifDecoder.Frames.Count / TimeD - _gifDecoder.Frames.Count / Time) * 1000)))); _animation.RepeatBehavior = RepeatBehavior.Forever; this.Source = _gifDecoder.Frames[0]; _isInitialized = true; }
// Constructors need to call this private void Initialize() { var gifDecoder = new GifBitmapDecoder(_stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); FrameCount = gifDecoder.Frames.Count; MetaData = gifDecoder.Metadata.ToList(); _frameDimension = new FrameDimension(_image.FrameDimensionsList.First()); Frames = GetFrames(_image, FrameCount, _frameDimension); FrameRates = GetFrameRates(_image, FrameCount); }
//Soulblighter Modification public void GetGifPalette(Bitmap bit) { using (MemoryStream imageStreamSource = new MemoryStream()) { System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter(); byte[] btImage = (byte[])ic.ConvertTo(bit, typeof(byte[])); imageStreamSource.Write(btImage, 0, btImage.Length); GifBitmapDecoder decoder = new GifBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapPalette pal = decoder.Palette; int i; for (i = 0; i < 0x100; i++) { this.Palette[i] = 0; } try { i = 0; while (i < 0x100)//&& i < pal.Colors.Count) { int Red = pal.Colors[i].R / 8; int Green = pal.Colors[i].G / 8; int Blue = pal.Colors[i].B / 8; int contaFinal = (((0x400 * Red) + (0x20 * Green)) + Blue) + 0x8000; if (contaFinal == 0x8000) contaFinal = 0x8001; this.Palette[i] = (ushort)contaFinal; i++; } } catch (System.IndexOutOfRangeException) { } catch (System.ArgumentOutOfRangeException) { } for (i = 0; i < 0x100; i++) { if (this.Palette[i] < 0x8000) this.Palette[i] = 0x8000; } } }