Beispiel #1
0
        public bool Save(Stream stream)
        {
            Contract.Assert(stream != null && stream.CanWrite && stream.CanSeek && stream.Position == 0);
            ImageFileHeader ifh          = new ImageFileHeader();
            var             nextIfdIndex = 8;
            bool            isBigEndian  = false;

            ifh.Save(stream, isBigEndian, nextIfdIndex);
            for (var i = 0; i < frameList.Count; i++)
            {
                var frame     = frameList[i];
                var isLastOne = i == frameList.Count - 1;
                frame.Save(stream, isBigEndian, isLastOne);
            }
            return(true);
        }
Beispiel #2
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);
        }