Пример #1
0
        /// <summary>
        /// Verifies that a JPEG File Interchange Format image falls inside the
        /// AOL-required dimensions:  between 48x48 and 50x50
        /// </summary>
        /// <param name="fs">
        /// An opened <see cref="FileStream"/> two bytes into the JFIF.
        /// </param>
        /// <returns>
        /// <c>true</c> if the JFIF fits in the required dimensions,
        /// <c>false</c> otherwise.
        /// </returns>
        private static bool VerifyJFIF(FileStream fs)
        {
            // Scroll to the Start Frame 0 position in the image
            bool foundframe0 = false;

            while (!foundframe0 && fs.Position < fs.Length)
            {
                if (fs.ReadByte() == 0xFF && fs.ReadByte() == 0xC0)
                {
                    break;
                }
            }
            if (fs.Position == fs.Length)
            {
                return(false);
            }

            // Three skip bytes, then the next four are the width and height (in NBO format)
            byte[] size = new byte[7];
            if (fs.Read(size, 0, size.Length) != size.Length)
            {
                return(false);
            }

            ushort height = 0, width = 0;

            using (ByteStream bstream = new ByteStream(size))
            {
                bstream.AdvanceToPosition(3);
                height = bstream.ReadUshort();
                width  = bstream.ReadUshort();
            }
            return((width >= 48 && width <= 50) && (height >= 48 && height <= 50));
        }