图形控制扩展(Graphic Control Extension)这一部分是可选的(需要89a版本), 可以放在一个图象块(包括图象标识符、局部颜色列表和图象数据)或文本扩展块的前面, 用来控制跟在它后面的第一个图象(或文本)的渲染(Render)形式
Inheritance: ExData
Example #1
0
        /// <summary>
        /// 从文件数据流中读取图形控制扩展(Graphic Control Extension)
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public GraphicEx GetGraphicControlExtension(Stream stream)
        {
            GraphicEx gex       = new GraphicEx();
            int       blockSize = Read();

            if (blockSize != GraphicEx.BlockSize)
            {
                throw new Exception("数据格式错误!");
            }
            gex.Packed           = (byte)Read();
            gex.TransparencyFlag = (gex.Packed & 0x01) == 1;
            gex.DisposalMethod   = (gex.Packed & 0x1C) >> 2;
            gex.Delay            = ReadShort();
            gex.TranIndex        = (byte)Read();
            Read();
            return(gex);
        }
Example #2
0
        internal static GifImage Decode(Stream stream)
        {
            StreamHelper     streamHelper = null;
            GifImage         gifImage     = new GifImage();
            List <GraphicEx> graphics     = new List <GraphicEx>();
            int frameCount = 0;

            try
            {
                streamHelper = new StreamHelper(stream);
                //读取文件头
                gifImage.Header = streamHelper.ReadString(6);
                //读取逻辑屏幕标示符
                gifImage.LogicalScreenDescriptor = streamHelper.GetLCD(stream);
                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, stream, gifImage, graphics, frameCount);
                        frameCount++;
                    }
                    else if (nextFlag == GifExtensions.ExtensionIntroducer)
                    {
                        int gcl = streamHelper.Read();
                        switch (gcl)
                        {
                        case GifExtensions.GraphicControlLabel:
                        {
                            GraphicEx graphicEx = streamHelper.GetGraphicControlExtension(stream);
                            graphics.Add(graphicEx);
                            break;
                        }

                        case GifExtensions.CommentLabel:
                        {
                            CommentEx comment = streamHelper.GetCommentEx(stream);
                            gifImage.CommentExtensions.Add(comment);
                            break;
                        }

                        case GifExtensions.ApplicationExtensionLabel:
                        {
                            ApplicationEx applicationEx = streamHelper.GetApplicationEx(stream);
                            gifImage.ApplictionExtensions.Add(applicationEx);
                            break;
                        }

                        case GifExtensions.PlainTextLabel:
                        {
                            PlainTextEx textEx = streamHelper.GetPlainTextEx(stream);
                            gifImage.PlainTextEntensions.Add(textEx);
                            break;
                        }
                        }
                    }
                    else if (nextFlag == GifExtensions.EndIntroducer)
                    {
                        //到了文件尾
                        break;
                    }
                    nextFlag = streamHelper.Read();
                }

                gifImage.Texture = new Texture2D(gifImage.Width, gifImage.Height, TextureFormat.ARGB32, false);
            }
            catch
            {
                throw;
            }
            finally
            {
                stream.Close();
            }
            return(gifImage);
        }
Example #3
0
        /// <summary>
        /// 对gif图像文件进行解码
        /// </summary>
        /// <param name="gifPath">gif文件路径</param>
        public static GifImage Decode(string gifPath)
        {
            FileStream       fs           = null;
            StreamHelper     streamHelper = null;
            GifImage         gifImage     = new GifImage();
            List <GraphicEx> graphics     = new List <GraphicEx>();
            int frameCount = 0;

//            try
//            {
            fs           = new FileStream(gifPath, FileMode.Open);
            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();
            }
//            }
//            catch
//            {
//                throw;
//            }
//            finally
//            {
            fs.Close();
//            }
            return(gifImage);
        }
Example #4
0
 /// <summary>
 /// 从文件数据流中读取图形控制扩展(Graphic Control Extension)
 /// </summary>
 /// <param name="stream"></param>
 /// <returns></returns>
 internal GraphicEx GetGraphicControlExtension(Stream stream)
 {
     GraphicEx gex = new GraphicEx();
     int blockSize = Read();
     if (blockSize != GraphicEx.BlockSize)
     {
         throw new Exception("数据格式错误!");
     }
     gex.Packed = (byte)Read();
     gex.TransparencyFlag = (gex.Packed & 0x01) == 1;
     gex.DisposalMethod = (gex.Packed & 0x1C) >> 2;
     gex.Delay = ReadShort();
     gex.TranIndex = (byte)Read();
     Read();
     return gex;
 }