コード例 #1
0
        static void ReadImage(StreamHelper streamHelper, Stream fs, GifImage gifImage, List <GraphicEx> graphics, int frameCount)
        {
            ImageDescriptor imgDes = streamHelper.GetImageDescriptor(fs);
            GifFrame        frame  = new GifFrame();

            frame.ImageDescriptor = imgDes;
            frame.LocalColorTable = gifImage.GlobalColorTable;
            if (imgDes.LctFlag)
            {
                frame.LocalColorTable = streamHelper.ReadByte(imgDes.LctSize * 3);
            }
            LZWDecoder lzwDecoder = new LZWDecoder(fs);
            int        dataSize   = streamHelper.Read();

            frame.ColorDepth = dataSize;
            byte[] piexel = lzwDecoder.DecodeImageData(imgDes.Width, imgDes.Height, dataSize);
            frame.IndexedPixel = piexel;
            int        blockSize = streamHelper.Read();
            DataStruct data      = new DataStruct(blockSize, fs);

            if (graphics.Count > frameCount)
            {
                GraphicEx graphicEx = graphics[frameCount];
                frame.GraphicExtension = graphicEx;
            }
            Bitmap img = GetImageFromPixel(piexel, frame.Palette, imgDes.InterlaceFlag, imgDes.Width, imgDes.Height);

            frame.Image = img;
            gifImage.Frames.Add(frame);
        }
コード例 #2
0
ファイル: StreamHelper.cs プロジェクト: nathanaeljones/GifLib
 /// <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;
 }
コード例 #3
0
        /// <summary>
        /// 从文件流中读取应用程序扩展块
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public 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);
        }
コード例 #4
0
ファイル: GifDecoder.cs プロジェクト: nathanaeljones/GifLib
 static void ReadImage(StreamHelper streamHelper, Stream fs, GifImage gifImage, List<GraphicEx> graphics, int frameCount)
 {
     ImageDescriptor imgDes = streamHelper.GetImageDescriptor(fs);
     GifFrame frame = new GifFrame();
     frame.ImageDescriptor = imgDes;
     frame.LocalColorTable = gifImage.GlobalColorTable;
     if (imgDes.LctFlag)
     {
         frame.LocalColorTable = streamHelper.ReadByte(imgDes.LctSize*3);
     }
     LZWDecoder lzwDecoder = new LZWDecoder(fs);
     int dataSize = streamHelper.Read();
     frame.ColorDepth = dataSize;
     byte[] piexel = lzwDecoder.DecodeImageData(imgDes.Width, imgDes.Height, dataSize);
     frame.IndexedPixel = piexel;
     int blockSize = streamHelper.Read();
     DataStruct data = new DataStruct(blockSize, fs);
     GraphicEx graphicEx = graphics[frameCount];
     frame.GraphicExtension = graphicEx;
     Bitmap img = GetImageFromPixel(piexel, frame.Palette, imgDes.InterlaceFlag, imgDes.Width, imgDes.Height);
     frame.Image = img;
     gifImage.Frames.Add(frame);
 }