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 に答える