public void AddImage(Bitmap image, float delayTime) { var gceBlock = new GifGraphicControlExtensionBlock(); gceBlock.DelayTime = delayTime; _structure.Blocks.Add(gceBlock); //var temp = new Bitmap(image); //if (_lastImage != null) { // generateDifference(_lastImage, image); //} //_lastImage = temp; image = _colorReductor.ReduceColor(image, 254); // image を GIF に変換し、そこから Image Block を抜き出して移植する using (var frameGif = new GifStructure(image)) { var imageBlock = (GifImageBlock)frameGif.Blocks.FirstOrDefault(p => p is GifImageBlock); if (imageBlock == null) throw new FormatException("Image block not found."); if (imageBlock.HasLocalColorTable) { // ローカルカラーテーブルがある場合 → 何もしない } else if (frameGif.Descriptor.HasGlobalColorTable) { // グローバルカラーテーブルがある場合 → ローカルに組み替える imageBlock.HasLocalColorTable = true; imageBlock.Raw_LocalColorTable = frameGif.Raw_GlobalColorTable; imageBlock.SizeOfLocalColorTable = frameGif.Descriptor.SizeOfGlobalColorTable; } else { throw new FormatException("Color table not found."); } frameGif.Blocks.Remove(imageBlock); _structure.Blocks.Add(imageBlock); } }
public GifAnimationGenerator(Size size, int loopCount = InfinityLoop) { var descriptor = new GifLogicalScreenDescriptor(); descriptor.BitsPerColorChannel = 8; descriptor.GlobalColorTableIsSorted = false; descriptor.HasGlobalColorTable = false; descriptor.PixelAspectRatio = 1; descriptor.SizeOfGlobalColorTable = 2; descriptor.Raw_Width = (UInt16)size.Width; descriptor.Raw_Height = (UInt16)size.Height; _structure = new GifStructure(descriptor); var appExtBlock = new GifApplicationExtensionBlock(); appExtBlock.Raw_ApplicationIdentifier = "NETSCAPE"; appExtBlock.Raw_ApplicationAuthenticationCode = "2.0"; var loopCountH = (byte)((loopCount >> 8) & 0xff); var loopCountL = (byte)((loopCount >> 0) & 0xff); appExtBlock.Raw_Data = new byte[] { 0x01, loopCountL, loopCountH }; _structure.Blocks.Add(appExtBlock); }