private void init(Stream stream, GIFFrameUpdatedCallbackMethod frameUpdatedCallback) { // set gif frame update callback this.FrameUpdatedCallback = frameUpdatedCallback; // decode gif image var gifDecoder = new GifDecoder(); var image = new ExtendedImage(); gifDecoder.Decode(image, stream); // add frames and load unity textures frames = new List <TextureGIFFrame>(); var firstFrame = new TextureGIFFrame(createTexture(image.PixelWidth, image.PixelHeight, image.Pixels), TimeSpan.FromSeconds(image.DelayTime / 100d)); frames.Add(firstFrame); var lastFrame = firstFrame; foreach (var frame in image.Frames) { var newFrame = new TextureGIFFrame(createTexture(frame.PixelWidth, frame.PixelHeight, frame.Pixels), TimeSpan.FromSeconds(frame.DelayTime / 100d)); frames.Add(newFrame); if (lastFrame != null) { lastFrame.nextFrame = newFrame; } lastFrame = newFrame; } // set starting image CurrentFrame = frames[0]; lastFrame.nextFrame = firstFrame; }
/// <summary> /// Construct gif from byte array /// </summary> /// <param name="data">Image data</param> /// <param name="frameUpdatedCallback">Called when gif frame texture has updated</param> public TextureGIF(byte[] data, GIFFrameUpdatedCallbackMethod frameUpdatedCallback) { using (var stream = new MemoryStream(data)) { stream.Position = 0; init(stream, frameUpdatedCallback); } }
/// <summary> /// Construct gif from stream /// </summary> /// <param name="stream">Image Stream</param> /// <param name="frameUpdatedCallback">Called when gif frame texture has updated</param> public TextureGIF(Stream stream, GIFFrameUpdatedCallbackMethod frameUpdatedCallback) { init(stream, frameUpdatedCallback); }
private void init(Stream stream, GIFFrameUpdatedCallbackMethod frameUpdatedCallback) { // set gif frame update callback this.FrameUpdatedCallback = frameUpdatedCallback; // decode gif image var gifDecoder = new GifDecoder(); var image = new ExtendedImage(); gifDecoder.Decode(image, stream); // add frames and load unity textures frames = new List<TextureGIFFrame>(); var firstFrame = new TextureGIFFrame(createTexture(image.PixelWidth, image.PixelHeight, image.Pixels), TimeSpan.FromSeconds(image.DelayTime / 100d)); frames.Add(firstFrame); var lastFrame = firstFrame; foreach (var frame in image.Frames) { var newFrame = new TextureGIFFrame(createTexture(frame.PixelWidth, frame.PixelHeight, frame.Pixels), TimeSpan.FromSeconds(frame.DelayTime / 100d)); frames.Add(newFrame); if (lastFrame != null) lastFrame.nextFrame = newFrame; lastFrame = newFrame; } // set starting image CurrentFrame = frames[0]; lastFrame.nextFrame = firstFrame; }