Пример #1
0
        public static Image Load(Stream stream)
        {
            if (stream == null || !stream.CanRead)
            {
                throw new ArgumentException("Invalid parameter. Stream must be readable", "imageStream");
            }

            Stream       seekedStream = stream;
            MemoryStream memstream    = null;

            if (!stream.CanSeek)
            {
                memstream = new MemoryStream();
                stream.CopyTo(memstream);

                memstream.Seek(0, SeekOrigin.Begin);
                seekedStream = memstream;
            }

            ImageDescription description = default(ImageDescription);

            DataBox[] dataBoxes = null;
            using (BinaryReader reader = new BinaryReader(seekedStream))
            {
                IDecoder decoder = FindDecoder(reader);
                decoder.DecodeData(reader, out dataBoxes, out description);
            }

            memstream?.Dispose();

            return(new Image(description, dataBoxes));
        }