0

给定一个 PICT 图像文件(文件格式的任一版本),我如何从标题数据中读取宽度和高度?

例如,这是我为 GIF 文件确定此信息的方式:

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)
4

1 回答 1

2

我相信您会发现 PICT 文件有一个 512 字节的标头,后跟文件大小和图像尺寸。

[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

坐标以 72 dpi 存储。

知道了这一点,你就可以计算出图像的高度和宽度了:)

于 2013-01-08T04:47:32.573 回答