private static void TransformFrame(IBitmapProcessor bitmapProcessor, ImageFrame frame) { var bitmapCopy = (Bitmap)frame.Bitmap.Clone(); frame.Bitmap.Dispose(); frame.Bitmap = bitmapProcessor.Process(bitmapCopy, frame.GetBackgroundColor().Color); DefaultQuantizer.Quantize(frame.Bitmap, frame.GetPalette()); frame.ImageDescriptor.ImageWidth = (short)frame.Bitmap.Width; frame.ImageDescriptor.ImageHeight = (short)frame.Bitmap.Height; }
private static ImageFrame ReadImageFrame(Stream stream, byte[] globalColorTable, GraphicControlExtension graphicControlExtension) { var imageDescriptor = ImageDescriptor.Read(stream); var imageFrame = new ImageFrame { ImageDescriptor = imageDescriptor, LocalColorTable = globalColorTable, GraphicControlExtension = graphicControlExtension }; if (imageDescriptor.LocalColorTableFlag) { imageFrame.LocalColorTable = stream.ReadBytes(imageDescriptor.LocalColorTableSize * 3); } imageFrame.ColorDepth = stream.ReadByte(); var lzwDecoder = new LzwDecoder(stream); var imageData = lzwDecoder.DecodeImageData(imageDescriptor.ImageWidth, imageDescriptor.ImageHeight, imageFrame.ColorDepth); ApplicationData.Read(stream); imageFrame.Bitmap = CreateBitmap( imageData, imageFrame.GetPalette(), imageDescriptor.InterlaceFlag, imageDescriptor.ImageWidth, imageDescriptor.ImageHeight); return imageFrame; }