注释扩展(Comment Extension) 这一部分是可选的(需要89a版本),可以用来记录图形、版权、描述等任何的非图形和控制 的纯文本数据(7-bit ASCII字符),注释扩展并不影响对图象数据流的处理,解码器完全可以忽 略它。存放位置可以是数据流的任何地方,最好不要妨碍控制和数据块,推荐放在数据流的开始或结尾
Пример #1
0
        public CommentEx GetCommentEx(Stream stream)
        {
            CommentEx    cmtEx        = new CommentEx();
            StreamHelper streamHelper = new StreamHelper(stream);

            cmtEx.CommentDatas = new List <string>();
            int nextFlag = streamHelper.Read();

            cmtEx.CommentDatas = new List <string>();
            while (nextFlag != 0)
            {
                int    blockSize = nextFlag;
                string data      = streamHelper.ReadString(blockSize);
                cmtEx.CommentDatas.Add(data);
                nextFlag = streamHelper.Read();
            }
            return(cmtEx);
        }
Пример #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);
        }
Пример #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);
        }
Пример #4
0
 internal CommentEx GetCommentEx(Stream stream)
 {
     CommentEx cmtEx = new CommentEx();
     StreamHelper streamHelper = new StreamHelper(stream);
     cmtEx.CommentDatas = new List<string>();
     int nextFlag = streamHelper.Read();
     cmtEx.CommentDatas = new List<string>();
     while (nextFlag != 0)
     {
         int blockSize = nextFlag;
         string data = streamHelper.ReadString(blockSize);
         cmtEx.CommentDatas.Add(data);
         nextFlag = streamHelper.Read();
     }
     return cmtEx;
 }