public void LoadGifPicture(Image img, GIFQuality quality) { List <byte> dataList; using (MemoryStream ms = new MemoryStream()) { img.SaveGIF(ms, quality); dataList = new List <byte>(ms.ToArray()); } if (!AnalyzeGifSignature(dataList)) { throw new Exception("File is not a gif!"); } AnalyzeScreenDescriptor(dataList); GIFBlockType blockType = GetTypeOfNextBlock(dataList); while (blockType != GIFBlockType.Trailer) { switch (blockType) { case GIFBlockType.ImageDescriptor: AnalyzeImageDescriptor(dataList); break; case GIFBlockType.Extension: ThrowAwayExtensionBlock(dataList); break; } blockType = GetTypeOfNextBlock(dataList); } }
public void LoadGifPicture(MemoryStream stream) { //TODO: Eliminate double copying List <byte> dataList = new List <byte>(stream.ToArray()); //Copies the data *again* grr. if (!AnalyzeGifSignature(dataList)) { throw (new Exception("File is not a gif!")); } AnalyzeScreenDescriptor(dataList); GIFBlockType blockType = GetTypeOfNextBlock(dataList); while (blockType != GIFBlockType.Trailer) { switch (blockType) { case GIFBlockType.ImageDescriptor: AnalyzeImageDescriptor(dataList); break; case GIFBlockType.Extension: ThrowAwayExtensionBlock(dataList); break; default: break; } blockType = GetTypeOfNextBlock(dataList); } }
public void LoadGifPicture(Bitmap gifPicture) { MemoryStream stream = new MemoryStream(); m_Image = gifPicture; m_Image.Save(stream, ImageFormat.Gif); List <byte> dataList = new List <byte>(stream.ToArray()); if (!AnalyzeGifSignature(dataList)) { throw (new Exception("File is not a gif!")); } AnalyzeScreenDescriptor(dataList); GIFBlockType blockType = GetTypeOfNextBlock(dataList); while (blockType != GIFBlockType.Trailer) { switch (blockType) { case GIFBlockType.ImageDescriptor: AnalyzeImageDescriptor(dataList); break; case GIFBlockType.Extension: ThrowAwayExtensionBlock(dataList); break; default: break; } blockType = GetTypeOfNextBlock(dataList); } }
private GIFBlockType GetTypeOfNextBlock(List <byte> gifData) { GIFBlockType blockType = (GIFBlockType)gifData[0]; return(blockType); }