Example #1
0
 /// <exception cref="Com.Drew.Imaging.Png.PngProcessingException"/>
 public PngHeader([NotNull] sbyte[] bytes)
 {
     if (bytes.Length != 13)
     {
         throw new PngProcessingException("PNG header chunk must have 13 data bytes");
     }
     SequentialReader reader = new SequentialByteArrayReader(bytes);
     try
     {
         _imageWidth = reader.GetInt32();
         _imageHeight = reader.GetInt32();
         _bitsPerSample = reader.GetInt8();
         sbyte colorTypeNumber = reader.GetInt8();
         PngColorType colorType = PngColorType.FromNumericValue(colorTypeNumber);
         if (colorType == null)
         {
             throw new PngProcessingException("Unexpected PNG color type: " + colorTypeNumber);
         }
         _colorType = colorType;
         _compressionType = reader.GetInt8();
         _filterMethod = reader.GetInt8();
         _interlaceMethod = reader.GetInt8();
     }
     catch (IOException e)
     {
         // Should never happen
         throw new PngProcessingException(e);
     }
 }
Example #2
0
        /// <exception cref="Com.Drew.Imaging.Png.PngProcessingException"/>
        public PngHeader(sbyte[] bytes)
        {
            if (bytes.Length != 13)
            {
                throw new PngProcessingException("PNG header chunk must have 13 data bytes");
            }
            SequentialReader reader = new SequentialByteArrayReader(bytes);

            try
            {
                _imageWidth    = reader.GetInt32();
                _imageHeight   = reader.GetInt32();
                _bitsPerSample = reader.GetInt8();
                sbyte        colorTypeNumber = reader.GetInt8();
                PngColorType colorType       = PngColorType.FromNumericValue(colorTypeNumber);
                if (colorType == null)
                {
                    throw new PngProcessingException("Unexpected PNG color type: " + colorTypeNumber);
                }
                _colorType       = colorType;
                _compressionType = reader.GetInt8();
                _filterMethod    = reader.GetInt8();
                _interlaceMethod = reader.GetInt8();
            }
            catch (IOException e)
            {
                // Should never happen
                throw new PngProcessingException(e);
            }
        }