public void SetSource(Stream stream) { Stream = stream; if (Stream == null) { //throw new InvalidDataException("Missing valid URI or Stream."); return; } _gifDecoder = new GifDecoder(Stream); _bgWorker = new GifBackgroundWorker(_gifDecoder); var pixSize = new PixelSize(_gifDecoder.Header.Dimensions.Width, _gifDecoder.Header.Dimensions.Height); _targetBitmap = new WriteableBitmap(pixSize, new Vector(96, 96), PixelFormat.Bgra8888, AlphaFormat.Opaque); _bgWorker.CurrentFrameChanged += FrameChanged; GifPixelSize = pixSize; Run(); }
public void SetSource(object newValue) { var sourceUri = newValue as Uri; var sourceStr = newValue as Stream; Stream stream = null; if (sourceUri != null) { _streamCanDispose = true; this.Progress = new Progress <int>(); if (sourceUri.OriginalString.Trim().StartsWith("resm")) { var assetLocator = AvaloniaLocator.Current.GetService <IAssetLoader>(); stream = assetLocator.Open(sourceUri); } } else if (sourceStr != null) { stream = sourceStr; } else { throw new InvalidDataException("Missing valid URI or Stream."); } Stream = stream; this._gifDecoder = new GifDecoder(Stream); this._bgWorker = new GifBackgroundWorker(_gifDecoder); var pixSize = new PixelSize(_gifDecoder.Header.Dimensions.Width, _gifDecoder.Header.Dimensions.Height); this._targetBitmap = new WriteableBitmap(pixSize, new Vector(96, 96), PixelFormat.Bgra8888); TargetControl.Source = _targetBitmap; //TargetControl.DetachedFromVisualTree += delegate { this.Dispose(); }; _bgWorker.CurrentFrameChanged += FrameChanged; Run(); }
public void Process() { GifRepeatBehavior gifRepeatBehavior = new GifRepeatBehavior(); if (_iterationCount.IsInfinite) { gifRepeatBehavior.LoopForever = true; } else { gifRepeatBehavior.LoopForever = false; gifRepeatBehavior.Count = (int)_iterationCount.Value; } _gifDecoder = new GifDecoder(_stream); var pixSize = new PixelSize(_gifDecoder.Header.Dimensions.Width, _gifDecoder.Header.Dimensions.Height); _targetBitmap = new WriteableBitmap(pixSize, new Vector(96, 96), PixelFormat.Bgra8888); _targerImage.Source = _targetBitmap; _bgWorker = new GifBackgroundWorker(_gifDecoder, gifRepeatBehavior); _bgWorker.CurrentFrameChanged += FrameChanged; Run(); }