/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // Load image data into memory using (var stream = File.OpenRead(_filePath)) { if (!_isAnimatedGif) { var image = ImageResult.FromStream(stream, ColorComponents.RedGreenBlueAlpha); var texture = new Texture2D(GraphicsDevice, image.Width, image.Height, false, SurfaceFormat.Color); texture.SetData(image.Data); var frame = new FrameInfo { Texture = texture, DelayInMs = 0 }; _frames.Add(frame); } else { _totalDelayInMs = 0; foreach (var image in ImageResult.AnimatedGifFramesFromStream(stream)) { var texture = new Texture2D(GraphicsDevice, image.Width, image.Height, false, SurfaceFormat.Color); texture.SetData(image.Data); var frame = new FrameInfo { Texture = texture, DelayInMs = image.DelayInMs }; _totalDelayInMs += frame.DelayInMs; _frames.Add(frame); } } } }
public void AnimatedGifFrames(string fileName, int width, int height, ColorComponents colorComponents, int originalFrameCount) { using (var stream = _assembly.OpenResourceStream(fileName)) { var frameCount = 0; foreach (var frame in ImageResult.AnimatedGifFramesFromStream(stream)) { Assert.AreEqual(frame.Width, width); Assert.AreEqual(frame.Height, height); Assert.AreEqual(frame.Comp, colorComponents); Assert.IsNotNull(frame.Data); Assert.AreEqual(frame.Data.Length, frame.Width * frame.Height * (int)frame.Comp); ++frameCount; } Assert.AreEqual(frameCount, originalFrameCount); stream.Seek(0, SeekOrigin.Begin); } Assert.AreEqual(MemoryStats.Allocations, 0); }