Ejemplo n.º 1
0
        /// <summary>
        /// Create a standard Bitmap object from a Stream. Will automatically
        /// detect the format of the image.
        /// </summary>
        /// <param name="stream">Stream from which the image will be read.</param>
        /// <returns>Bitmap that contains the decoded image, or null if it could
        /// not be decoded by any of the formats known to this library.</returns>
        public static Bitmap Load(Stream stream)
        {
            Bitmap bmp = null;

            //read the first few bytes of the file to determine what format it is...
            byte[] header = new byte[256];
            stream.Read(header, 0, header.Length);
            stream.Seek(0, SeekOrigin.Begin);

            if ((header[0] == 0xA) && (header[1] >= 0x3) && (header[1] <= 0x5) && (header[2] == 0x1) && ((header[3] == 0x1) || (header[3] == 0x2) || (header[3] == 0x4) || (header[3] == 0x8)))
            {
                bmp = PcxReader.Load(stream);
            }
            else if ((header[0] == 'P') && ((header[1] >= '1') && (header[1] <= '6')) && ((header[2] == 0xA) || (header[2] == 0xD) || (header[2] == 0x20)))
            {
                bmp = PnmReader.Load(stream);
            }
            else if ((header[0] == 0x59) && (header[1] == 0xa6) && (header[2] == 0x6a) && (header[3] == 0x95))
            {
                bmp = RasReader.Load(stream);
            }
            else if ((header[0x80] == 'D') && (header[0x81] == 'I') && (header[0x82] == 'C') && (header[0x83] == 'M'))
            {
                bmp = DicomReader.Load(stream);
            }

            return(bmp);
        }
Ejemplo n.º 2
0
        public static Bitmap Load(Stream stream)
        {
            Bitmap result = null;
            var    array  = new byte[256];

            stream.Read(array, 0, array.Length);
            stream.Seek(0L, SeekOrigin.Begin);
            if (array[0] == 10 && array[1] >= 3 && array[1] <= 5 && array[2] == 1 && array[4] == 0 && array[5] == 0)
            {
                result = PcxReader.Load(stream);
            }
            else if (array[0] == 80 && array[1] >= 49 && array[1] <= 54 && (array[2] == 10 || array[2] == 13))
            {
                result = PnmReader.Load(stream);
            }
            else if (array[0] == 89 && array[1] == 166 && array[2] == 106 && array[3] == 149)
            {
                result = RasReader.Load(stream);
            }
            else if (array[128] == 68 && array[129] == 73 && array[130] == 67 && array[131] == 77)
            {
                result = DicomReader.Load(stream);
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a standard Bitmap object from a Stream. Will automatically
        /// detect the format of the image.
        /// </summary>
        /// <param name="stream">Stream from which the image will be read.</param>
        /// <returns>Bitmap that contains the decoded image, or null if it could
        /// not be decoded by any of the formats known to this library.</returns>
        public static Bitmap Load(Stream stream)
        {
            //read the first few bytes of the file to determine what format it is...
            byte[] header = new byte[256];
            stream.Read(header, 0, header.Length);
            stream.Seek(0, SeekOrigin.Begin);

            Bitmap bmp;

            if (header[0] == 0xA && header[1] >= 0x3 && header[1] <= 0x5 && header[2] == 0x1 && header[4] == 0 && header[5] == 0)
            {
                bmp = PcxReader.Load(stream);
            }
            else if (header[0] == 'P' && header[1] >= '1' && header[1] <= '6' && (header[2] == 0xA || header[2] == 0xD))
            {
                bmp = PnmReader.Load(stream);
            }
            else if (header[0] == 0x59 && header[1] == 0xa6 && header[2] == 0x6a && header[3] == 0x95)
            {
                bmp = RasReader.Load(stream);
            }
            else if (header[0x80] == 'D' && header[0x81] == 'I' && header[0x82] == 'C' && header[0x83] == 'M')
            {
                bmp = DicomReader.Load(stream);
            }
            else
            {
                bmp = (Bitmap)Image.FromStream(stream);
            }

            return(bmp);
        }