0

C#のビットマップオブジェクトからBITMAPV5HEADERを取得する方法はありますか?または、その中にある値を取得しますか?ビットマップからColorSpace情報を取得する必要がありますが、C#でこれを行う方法がわかりません。

4

2 に答える 2

1

簡単な方法とは思えませんが、生データを読み込んでBITMAPV5HEADER構造体に変換するハックな (そしておそらく非常にバグの多い) 方法です。

構造
[StructLayout(LayoutKind.Sequential)]
public struct BITMAPV5HEADER
{
  uint bV5Size;
  long bV5Width;
  long bV5Height;
  int bV5Planes;
  int bV5BitCount;
  uint bV5Compression;
  uint bV5SizeImage;
  long bV5XPelsPerMeter;
  long bV5YPelsPerMeter;
  uint bV5ClrUsed;
  uint bV5ClrImportant;
  uint bV5RedMask;
  uint bV5GreenMask;
  uint bV5BlueMask;
  uint bV5AlphaMask;
  uint bV5CSType;
  IntPtr bV5Endpoints;
  uint bV5GammaRed;
  uint bV5GammaGreen;
  uint bV5GammaBlue;
  uint bV5Intent;
  uint bV5ProfileData;
  uint bV5ProfileSize;
  uint bV5Reserved;
}
ヘルパー メソッド
public static T RawStructureRead<T>(Stream stream) where T : struct
{
  T @struct;
  int size = Marshal.SizeOf(typeof(T));

  BinaryReader reader = new BinaryReader(stream);
  byte[] buffer = reader.ReadBytes(size);

  GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
  @struct = (T)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(T));
  handle.Free();

  return @struct;
}
使用法
using (FileStream stream = File.OpenRead("..."))
{
  BITMAPV5HEADER header = RawStructureRead<BITMAPV5HEADER>(stream);
}
于 2009-04-03T19:38:07.250 に答える
0

疑わしい。は、使用して作成されBITMAPV5HEADERた GDI+ ではなく、GDI オブジェクト用ですBitmap。可能であれば、標準の GDI 呼び出しを使用してファイルを再度開きます。

于 2009-04-03T19:37:30.620 に答える