Win32 API 日本語リファレンス
ホームGraphics.Gdi › BITMAPINFOHEADER

BITMAPINFOHEADER

構造体
サイズx64: 40 バイト / x86: 40 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
biSizeDWORD4+0+0この構造体のサイズ(バイト数)。ヘッダー種別の判別に用いる。
biWidthINT4+4+4ビットマップの幅(ピクセル数)。
biHeightINT4+8+8ビットマップの高さ。正でボトムアップ、負でトップダウン。
biPlanesWORD2+12+12対象デバイスのプレーン数。常に1。
biBitCountWORD2+14+141ピクセルあたりのビット数(色深度)。
biCompressionDWORD4+16+16ビットマップの圧縮形式(BI_RGB等)を示す値。
biSizeImageDWORD4+20+20画像データのバイト数。非圧縮なら0でも可。
biXPelsPerMeterINT4+24+24水平方向の解像度(1メートルあたりのピクセル数)。
biYPelsPerMeterINT4+28+28垂直方向の解像度(1メートルあたりのピクセル数)。
biClrUsedDWORD4+32+32実際に使用するカラーテーブルの色数。0で最大数を使用。
biClrImportantDWORD4+36+36表示に重要な色数。0で全色が重要。

各言語での定義

#include <windows.h>

// BITMAPINFOHEADER  (x64 40 / x86 40 バイト)
typedef struct BITMAPINFOHEADER {
    DWORD biSize;
    INT biWidth;
    INT biHeight;
    WORD biPlanes;
    WORD biBitCount;
    DWORD biCompression;
    DWORD biSizeImage;
    INT biXPelsPerMeter;
    INT biYPelsPerMeter;
    DWORD biClrUsed;
    DWORD biClrImportant;
} BITMAPINFOHEADER;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BITMAPINFOHEADER
{
    public uint biSize;
    public int biWidth;
    public int biHeight;
    public ushort biPlanes;
    public ushort biBitCount;
    public uint biCompression;
    public uint biSizeImage;
    public int biXPelsPerMeter;
    public int biYPelsPerMeter;
    public uint biClrUsed;
    public uint biClrImportant;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BITMAPINFOHEADER
    Public biSize As UInteger
    Public biWidth As Integer
    Public biHeight As Integer
    Public biPlanes As UShort
    Public biBitCount As UShort
    Public biCompression As UInteger
    Public biSizeImage As UInteger
    Public biXPelsPerMeter As Integer
    Public biYPelsPerMeter As Integer
    Public biClrUsed As UInteger
    Public biClrImportant As UInteger
End Structure
import ctypes
from ctypes import wintypes

class BITMAPINFOHEADER(ctypes.Structure):
    _fields_ = [
        ("biSize", wintypes.DWORD),
        ("biWidth", ctypes.c_int),
        ("biHeight", ctypes.c_int),
        ("biPlanes", ctypes.c_ushort),
        ("biBitCount", ctypes.c_ushort),
        ("biCompression", wintypes.DWORD),
        ("biSizeImage", wintypes.DWORD),
        ("biXPelsPerMeter", ctypes.c_int),
        ("biYPelsPerMeter", ctypes.c_int),
        ("biClrUsed", wintypes.DWORD),
        ("biClrImportant", wintypes.DWORD),
    ]
#[repr(C)]
pub struct BITMAPINFOHEADER {
    pub biSize: u32,
    pub biWidth: i32,
    pub biHeight: i32,
    pub biPlanes: u16,
    pub biBitCount: u16,
    pub biCompression: u32,
    pub biSizeImage: u32,
    pub biXPelsPerMeter: i32,
    pub biYPelsPerMeter: i32,
    pub biClrUsed: u32,
    pub biClrImportant: u32,
}
import "golang.org/x/sys/windows"

type BITMAPINFOHEADER struct {
	biSize uint32
	biWidth int32
	biHeight int32
	biPlanes uint16
	biBitCount uint16
	biCompression uint32
	biSizeImage uint32
	biXPelsPerMeter int32
	biYPelsPerMeter int32
	biClrUsed uint32
	biClrImportant uint32
}
type
  BITMAPINFOHEADER = record
    biSize: DWORD;
    biWidth: Integer;
    biHeight: Integer;
    biPlanes: Word;
    biBitCount: Word;
    biCompression: DWORD;
    biSizeImage: DWORD;
    biXPelsPerMeter: Integer;
    biYPelsPerMeter: Integer;
    biClrUsed: DWORD;
    biClrImportant: DWORD;
  end;
const BITMAPINFOHEADER = extern struct {
    biSize: u32,
    biWidth: i32,
    biHeight: i32,
    biPlanes: u16,
    biBitCount: u16,
    biCompression: u32,
    biSizeImage: u32,
    biXPelsPerMeter: i32,
    biYPelsPerMeter: i32,
    biClrUsed: u32,
    biClrImportant: u32,
};
type
  BITMAPINFOHEADER {.bycopy.} = object
    biSize: uint32
    biWidth: int32
    biHeight: int32
    biPlanes: uint16
    biBitCount: uint16
    biCompression: uint32
    biSizeImage: uint32
    biXPelsPerMeter: int32
    biYPelsPerMeter: int32
    biClrUsed: uint32
    biClrImportant: uint32
struct BITMAPINFOHEADER
{
    uint biSize;
    int biWidth;
    int biHeight;
    ushort biPlanes;
    ushort biBitCount;
    uint biCompression;
    uint biSizeImage;
    int biXPelsPerMeter;
    int biYPelsPerMeter;
    uint biClrUsed;
    uint biClrImportant;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; BITMAPINFOHEADER サイズ: 40 バイト(x64)
dim st, 10    ; 4byte整数×10(構造体サイズ 40 / 4 切り上げ)
; biSize : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; biWidth : INT (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; biHeight : INT (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; biPlanes : WORD (+12, 2byte)  wpoke st,12,値  /  値 = wpeek(st,12)
; biBitCount : WORD (+14, 2byte)  wpoke st,14,値  /  値 = wpeek(st,14)
; biCompression : DWORD (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; biSizeImage : DWORD (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; biXPelsPerMeter : INT (+24, 4byte)  st.6 = 値  /  値 = st.6   (lpoke/lpeek も可)
; biYPelsPerMeter : INT (+28, 4byte)  st.7 = 値  /  値 = st.7   (lpoke/lpeek も可)
; biClrUsed : DWORD (+32, 4byte)  st.8 = 値  /  値 = st.8   (lpoke/lpeek も可)
; biClrImportant : DWORD (+36, 4byte)  st.9 = 値  /  値 = st.9   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global BITMAPINFOHEADER
    #field int biSize
    #field int biWidth
    #field int biHeight
    #field short biPlanes
    #field short biBitCount
    #field int biCompression
    #field int biSizeImage
    #field int biXPelsPerMeter
    #field int biYPelsPerMeter
    #field int biClrUsed
    #field int biClrImportant
#endstruct

stdim st, BITMAPINFOHEADER        ; NSTRUCT 変数を確保
st->biSize = 100
mes "biSize=" + st->biSize