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.
The coordinates are stored at 72 dpi.
Knowing this, you can calculate the image height and width 🙂