Ejemplo n.º 1
0
        public bool Save(Stream stream)
        {
            Contract.Requires(frameList.Count > 0);
            Contract.Requires(Unit != Unit.Unknown);

            var encode     = new TiffEncode();
            var properties = new Properties();

            properties.Compression   = Compression;
            properties.ColorType     = ColorType;
            properties.BytesPerPixel = BytesPerPixel;
            properties.Width         = Width;
            properties.Height        = Height;
            properties.Unit          = Unit;
            properties.XResolution   = XResolution;
            properties.YResolution   = YResolution;

            foreach (var frame in frameList)
            {
                var ifd = new ImageFileDirection(properties, frame.GetPixels());
                encode.AddFrame(ifd);
            }
            encode.Save(stream);
            return(true);
        }
Ejemplo n.º 2
0
 public bool AddFrame(ImageFileDirection frame)
 {
     Contract.Assert(frame != null);
     ;
     if (frameList.Contains(frame))
     {
         return(false);
     }
     frameList.Add(frame);
     return(true);
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="quickly">为true时,快速加载,只解析每个帧的头信息,而不解析所有内容(第一帧为完整加载)</param>
        /// <returns></returns>
        public bool Load(Stream stream, bool quickly = false)
        {
            var ifh = new ImageFileHeader();

            if (!ifh.Load(stream))
            {
                return(false);
            }

            IsBigEndian = ifh.IsBigEndian;
            //第一个IFD位置偏移
            var nextPosition = ifh.FirstFramePosition;

            while (true)
            {
                if (nextPosition != stream.Position)
                {
                    Contract.Requires(nextPosition > stream.Position);
                    stream.Position = nextPosition;
                }
                var ifd = new ImageFileDirection();
                if (quickly)
                {
                    ifd.LoadHeader(stream, IsBigEndian);
                }
                else
                {
                    ifd.Load(stream, IsBigEndian);
                }
                ImageFileDirectionList.Add(ifd);
                if (ifd.NextIfdIndex == 0)
                {
                    break;
                }
                nextPosition = ifd.NextIfdIndex;
            }
            Contract.Requires(ImageFileDirectionList.Count > 0);
            return(true);
        }