简体   繁体   中英

How to read width and height of PICT image files?

Given a PICT image file (either version of the file format), how can I read the width and height from the header data?

For example, this is how I determine this information for a GIF file:

using (FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read)) {
    int c1 = fs.ReadByte();
    int c2 = fs.ReadByte();
    int c3 = fs.ReadByte();

    if (c1 == 'G' && c2 == 'I' && c3 == 'F') {
        fs.Seek(3, SeekOrigin.Current);
        width = ReadInt(fs, 2, false);
        height = ReadInt(fs, 2, false);
        return true;
    }
}

// Signature for ReadInt:
// int ReadInt(FileStream fs, int bytes, bool bigEndian)

I believe you'll find that PICT files have a 512 byte header followed by the file size and image dimensions.

[Platform Header] - 512 byte
[File Size] - short
[Image Top Left x] - short
[Image Top Left y] - short
[Image Bottom Right x] - short
[Image Bottom Right y] - short

The coordinates are stored at 72 dpi.

Knowing this, you can calculate the image height and width :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM