/// <summary> /// 从文件流中读取应用程序扩展块 /// </summary> /// <param name="stream"></param> /// <returns></returns> internal ApplicationEx GetApplicationEx(Stream stream) { ApplicationEx appEx = new ApplicationEx(); int blockSize = Read(); if (blockSize != ApplicationEx.BlockSize) { throw new Exception("数据格式错误!"); } appEx.ApplicationIdentifier = ReadChar(8); appEx.ApplicationAuthenticationCode = ReadChar(3); int nextFlag = Read(); appEx.Datas = new List <DataStruct>(); while (nextFlag != 0) { DataStruct data = new DataStruct(nextFlag, stream); appEx.Datas.Add(data); nextFlag = Read(); } return(appEx); }
public static GifImage Decode(Stream fs) { StreamHelper streamHelper = null; GifImage gifImage = new GifImage(); List <GraphicEx> graphics = new List <GraphicEx>(); int frameCount = 0; streamHelper = new StreamHelper(fs); gifImage.Header = streamHelper.ReadString(6); gifImage.LogicalScreenDescriptor = streamHelper.GetLCD(fs); if (gifImage.LogicalScreenDescriptor.GlobalColorTableFlag) { gifImage.GlobalColorTable = streamHelper.ReadByte(gifImage.LogicalScreenDescriptor.GlobalColorTableSize * 3); } int nextFlag = streamHelper.Read(); while (nextFlag != 0) { if (nextFlag == GifExtensions.ImageLabel) { ReadImage(streamHelper, fs, gifImage, graphics, frameCount); frameCount++; } else if (nextFlag == GifExtensions.ExtensionIntroducer) { int gcl = streamHelper.Read(); switch (gcl) { case GifExtensions.GraphicControlLabel: { GraphicEx graphicEx = streamHelper.GetGraphicControlExtension(fs); graphics.Add(graphicEx); break; } case GifExtensions.CommentLabel: { CommentEx comment = streamHelper.GetCommentEx(fs); gifImage.CommentExtensions.Add(comment); break; } case GifExtensions.ApplicationExtensionLabel: { ApplicationEx applicationEx = streamHelper.GetApplicationEx(fs); gifImage.ApplictionExtensions.Add(applicationEx); break; } case GifExtensions.PlainTextLabel: { PlainTextEx textEx = streamHelper.GetPlainTextEx(fs); gifImage.PlainTextEntensions.Add(textEx); break; } } } else if (nextFlag == GifExtensions.EndIntroducer) { break; } nextFlag = streamHelper.Read(); } return(gifImage); }