Beispiel #1
0
        /// <summary>
        /// 从文件数据流中读取图形控制扩展(Graphic Control Extension)
        /// </summary>
        /// <param name="stream"></param>
        /// <returns></returns>
        public LogicalScreenDescriptor GetLCD(Stream stream)
        {
            LogicalScreenDescriptor lcd = new LogicalScreenDescriptor();

            lcd.Width  = ReadShort();
            lcd.Height = ReadShort();
            lcd.Packed = (byte)Read();
            lcd.GlobalColorTableFlag = ((lcd.Packed & 0x80) >> 7) == 1;
            lcd.ColorResoluTion      = (byte)((lcd.Packed & 0x60) >> 5);
            lcd.SortFlag             = (byte)(lcd.Packed & 0x10) >> 4;
            lcd.GlobalColorTableSize = 2 << (lcd.Packed & 0x07);
            lcd.BgColorIndex         = (byte)Read();
            lcd.PixcelAspect         = (byte)Read();
            return(lcd);
        }
Beispiel #2
0
        /// <summary>
        /// 合并多个gif动画,在空间坐标上
        /// </summary>
        /// <param name="sourceGifs">原图像</param>
        /// <param name="outPath">合并后图像</param>
        public static void Merge(List <string> sourceGifs, string outPath)
        {
            List <List <GifFrame> > frames = new List <List <GifFrame> >();

            foreach (string source in sourceGifs)
            {
                if (!File.Exists(source))
                {
                    throw new IOException(string.Format("文件{0}不存在!", source));
                }
                using (Bitmap ora_Img = new Bitmap(source))
                {
                    if (ora_Img.RawFormat.Guid != ImageFormat.Gif.Guid)
                    {
                        throw new IOException(string.Format("文件{0}!", source));
                    }
                }
                GifImage gifImage = GifDecoder.Decode(source);
                ThinkDisposalMethod(gifImage);
                int index = 0;
                foreach (GifFrame f in gifImage.Frames)
                {
                    if (frames.Count <= index)
                    {
                        List <GifFrame> list = new List <GifFrame>();
                        frames.Add(list);
                    }
                    List <GifFrame> frameList = frames[index];
                    frameList.Add(f);
                    index++;
                }
            }
            List <GifFrame> frameCol   = new List <GifFrame>();
            int             frameIndex = 0;

            foreach (List <GifFrame> fs in frames)
            {
                GifFrame frame = Merge(fs);
                frameCol.Add(frame);
                if (frame.Image.Width != frameCol[0].Image.Width ||
                    frame.Image.Height != frameCol[0].Image.Height)
                {
                    frame.ImageDescriptor.XOffSet         = frames[frameIndex][0].ImageDescriptor.XOffSet;
                    frame.ImageDescriptor.YOffSet         = frames[frameIndex][0].ImageDescriptor.YOffSet;
                    frame.GraphicExtension.DisposalMethod = frames[frameIndex][0].GraphicExtension.DisposalMethod;
                }
                frame.GraphicExtension.Delay = frame.Delay = frames[frameIndex][0].Delay;
                frameIndex++;
            }
            GifImage gifImg = new GifImage();

            gifImg.Header = "GIF89a";
            LogicalScreenDescriptor lcd = new LogicalScreenDescriptor();

            lcd.Width  = (short)frameCol[0].Image.Width;
            lcd.Height = (short)frameCol[0].Image.Height;
            gifImg.LogicalScreenDescriptor = lcd;
            ApplicationEx        ape  = new ApplicationEx();
            List <ApplicationEx> apps = new List <ApplicationEx>();

            apps.Add(ape);
            gifImg.ApplictionExtensions = apps;
            gifImg.Frames = frameCol;
            GifEncoder.Encode(gifImg, outPath);
        }
Beispiel #3
0
 /// <summary>
 /// 写逻辑屏幕标识符
 /// </summary>
 /// <param name="lsd"></param>
 public void WriteLSD(LogicalScreenDescriptor lsd)
 {
     WriteBytes(lsd.GetBuffer());
 }