Beispiel #1
0
        private static Size DecodeBitmap(SequentialBinaryReader reader)
        {
            var magicNumber = reader.ReadUInt16();

            // skip past the rest of the file header
            reader.Skip(4 + 2 + 2 + 4);

            int headerSize = reader.ReadInt32();
            int width, height;

            // We expect the header size to be either 40 (BITMAPINFOHEADER) or 12 (BITMAPCOREHEADER)
            if (headerSize == 40)
            {
                // BITMAPINFOHEADER
                width  = reader.ReadInt32();
                height = Math.Abs(reader.ReadInt32());
            }
            else if (headerSize == 12)
            {
                width  = reader.ReadInt16();
                height = reader.ReadInt16();
            }
            else
            {
                // Unexpected DIB header size
                return(Size.Empty);
            }

            return(new Size(width, height));
        }
Beispiel #2
0
        private static Size DecodePng(SequentialBinaryReader reader)
        {
            reader.IsBigEndian = true;
            reader.ReadBytes(pngSignatureBytes.Length);
            reader.Skip(8);

            int width  = reader.ReadInt32();
            int height = reader.ReadInt32();

            return(new Size(width, height));
        }
Beispiel #3
0
        private static Size DecodeEmf(SequentialBinaryReader reader)
        {
            // EMR_HEADER: Type + Size + Bounds
            reader.Skip(4 + 4 + 16);

            // Frame: specify the rectangular inclusive-inclusive dimensions,
            // in .01 millimeter units, of a rectangle that surrounds the image stored in the metafile.
            int left   = reader.ReadInt32();
            int top    = reader.ReadInt32();
            int right  = reader.ReadInt32();
            int bottom = reader.ReadInt32();

            // Skip other headers:
            // Signature (4) + Version (4) + Size (4) + Records (4) + Handles (2)
            // + nReserved (2) + nDescription (4) + offDescription (4) + PalEntries (4)
            reader.Skip(32);

            // Next 8 bytes specify the size of the reference device, in pixels
            int deviceSizeInPixelX = reader.ReadInt32();
            int deviceSizeInPixelY = reader.ReadInt32();

            // Then 8 more to specify the size of the reference device, in millimeters
            int deviceSizeInMlmX = reader.ReadInt32();
            int deviceSizeInMlmY = reader.ReadInt32();

            int widthInPixel  = (int)Math.Round(0.5 + ((right - left + 1.0) * deviceSizeInPixelX / deviceSizeInMlmX) / 100.0);
            int heightInPixel = (int)Math.Round(0.5 + ((bottom - top + 1.0) * deviceSizeInPixelY / deviceSizeInMlmY) / 100.0);

            return(new Size(widthInPixel, heightInPixel));
        }