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

BITMAPCOREINFO

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

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

フィールド

フィールドサイズx64x86説明
bmciHeaderBITMAPCOREHEADER12+0+0DIB の寸法と色形式に関する情報を格納する BITMAPCOREHEADER 構造体です。
bmciColorsRGBTRIPLE3+12+12ビットマップ内の色を定義する RGBTRIPLE 構造体の配列を指定します。

公式ドキュメント

BITMAPCOREINFO 構造体は、DIB の寸法と色情報を定義します。

解説(Remarks)

DIB は 2 つの部分で構成されます。ビットマップの寸法と色を記述する BITMAPCOREINFO 構造体と、ビットマップのピクセルを定義するバイト配列です。配列内のビットは詰めて格納されますが、各走査線は LONG 境界で終わるように 0 で埋める必要があります。ビットマップの原点は左下隅です。

BITMAPCOREHEADER 構造体の bcBitCount メンバーは、各ピクセルを定義するビット数と、ビットマップ内の最大色数を決定します。このメンバーには次のいずれかの値を指定できます。

意味
1 ビットマップはモノクロであり、bmciColors メンバーには 2 つのエントリが含まれます。ビットマップ配列内の各ビットが 1 つのピクセルを表します。ビットが 0 の場合、そのピクセルは bmciColors テーブルの 1 番目のエントリの色で表示されます。ビットが 1 の場合、そのピクセルはテーブルの 2 番目のエントリの色になります。
4 ビットマップは最大 16 色であり、bmciColors メンバーには最大 16 個のエントリが含まれます。ビットマップ内の各ピクセルは、カラーテーブルへの 4 ビットのインデックスで表されます。たとえば、ビットマップの最初のバイトが 0x1F の場合、このバイトは 2 つのピクセルを表します。1 番目のピクセルはテーブルの 2 番目のエントリの色を持ち、2 番目のピクセルはテーブルの 16 番目のエントリの色を持ちます。
8 ビットマップは最大 256 色であり、bmciColors メンバーには最大 256 個のエントリが含まれます。この場合、配列内の各バイトが 1 つのピクセルを表します。
24 ビットマップは最大 2 (24) 色であり、bmciColors メンバーは NULL です。ビットマップ配列内の 3 バイトの組それぞれが、1 つのピクセルにおける青、緑、赤の相対的な強度を表します。

bmciColors テーブル内の色は、重要度の高い順に並べる必要があります。

また、DIB を使用する関数では、bmciColors メンバーに明示的な RGB 値の代わりに、現在実現されている論理パレットへのインデックスを指定する 16 ビット符号なし整数の配列を指定することもできます。この場合、そのビットマップを使用するアプリケーションは、DIB 関数 ( CreateDIBitmapCreateDIBPatternBrushCreateDIBSection ) を、iUsage パラメーターに DIB_PAL_COLORS を設定して呼び出す必要があります。

ビットマップをファイルに保存する場合や、別のアプリケーションに転送する場合は、bmciColors メンバーにパレットインデックスを格納しないでください。アプリケーションがそのビットマップを排他的に使用および制御している場合を除き、ビットマップのカラーテーブルには明示的な RGB 値を格納する必要があります。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での定義

#include <windows.h>

// BITMAPCOREHEADER  (x64 12 / x86 12 バイト)
typedef struct BITMAPCOREHEADER {
    DWORD bcSize;
    WORD bcWidth;
    WORD bcHeight;
    WORD bcPlanes;
    WORD bcBitCount;
} BITMAPCOREHEADER;

// RGBTRIPLE  (x64 3 / x86 3 バイト)
typedef struct RGBTRIPLE {
    BYTE rgbtBlue;
    BYTE rgbtGreen;
    BYTE rgbtRed;
} RGBTRIPLE;

// BITMAPCOREINFO  (x64 16 / x86 16 バイト)
typedef struct BITMAPCOREINFO {
    BITMAPCOREHEADER bmciHeader;
    RGBTRIPLE bmciColors[1];
} BITMAPCOREINFO;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BITMAPCOREHEADER
{
    public uint bcSize;
    public ushort bcWidth;
    public ushort bcHeight;
    public ushort bcPlanes;
    public ushort bcBitCount;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct RGBTRIPLE
{
    public byte rgbtBlue;
    public byte rgbtGreen;
    public byte rgbtRed;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BITMAPCOREINFO
{
    public BITMAPCOREHEADER bmciHeader;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public RGBTRIPLE[] bmciColors;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BITMAPCOREHEADER
    Public bcSize As UInteger
    Public bcWidth As UShort
    Public bcHeight As UShort
    Public bcPlanes As UShort
    Public bcBitCount As UShort
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure RGBTRIPLE
    Public rgbtBlue As Byte
    Public rgbtGreen As Byte
    Public rgbtRed As Byte
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BITMAPCOREINFO
    Public bmciHeader As BITMAPCOREHEADER
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=1)> Public bmciColors() As RGBTRIPLE
End Structure
import ctypes
from ctypes import wintypes

class BITMAPCOREHEADER(ctypes.Structure):
    _fields_ = [
        ("bcSize", wintypes.DWORD),
        ("bcWidth", ctypes.c_ushort),
        ("bcHeight", ctypes.c_ushort),
        ("bcPlanes", ctypes.c_ushort),
        ("bcBitCount", ctypes.c_ushort),
    ]

class RGBTRIPLE(ctypes.Structure):
    _fields_ = [
        ("rgbtBlue", ctypes.c_ubyte),
        ("rgbtGreen", ctypes.c_ubyte),
        ("rgbtRed", ctypes.c_ubyte),
    ]

class BITMAPCOREINFO(ctypes.Structure):
    _fields_ = [
        ("bmciHeader", BITMAPCOREHEADER),
        ("bmciColors", RGBTRIPLE * 1),
    ]
#[repr(C)]
pub struct BITMAPCOREHEADER {
    pub bcSize: u32,
    pub bcWidth: u16,
    pub bcHeight: u16,
    pub bcPlanes: u16,
    pub bcBitCount: u16,
}

#[repr(C)]
pub struct RGBTRIPLE {
    pub rgbtBlue: u8,
    pub rgbtGreen: u8,
    pub rgbtRed: u8,
}

#[repr(C)]
pub struct BITMAPCOREINFO {
    pub bmciHeader: BITMAPCOREHEADER,
    pub bmciColors: [RGBTRIPLE; 1],
}
import "golang.org/x/sys/windows"

type BITMAPCOREHEADER struct {
	bcSize uint32
	bcWidth uint16
	bcHeight uint16
	bcPlanes uint16
	bcBitCount uint16
}

type RGBTRIPLE struct {
	rgbtBlue byte
	rgbtGreen byte
	rgbtRed byte
}

type BITMAPCOREINFO struct {
	bmciHeader BITMAPCOREHEADER
	bmciColors [1]RGBTRIPLE
}
type
  BITMAPCOREHEADER = record
    bcSize: DWORD;
    bcWidth: Word;
    bcHeight: Word;
    bcPlanes: Word;
    bcBitCount: Word;
  end;

  RGBTRIPLE = record
    rgbtBlue: Byte;
    rgbtGreen: Byte;
    rgbtRed: Byte;
  end;

  BITMAPCOREINFO = record
    bmciHeader: BITMAPCOREHEADER;
    bmciColors: array[0..0] of RGBTRIPLE;
  end;
const BITMAPCOREHEADER = extern struct {
    bcSize: u32,
    bcWidth: u16,
    bcHeight: u16,
    bcPlanes: u16,
    bcBitCount: u16,
};

const RGBTRIPLE = extern struct {
    rgbtBlue: u8,
    rgbtGreen: u8,
    rgbtRed: u8,
};

const BITMAPCOREINFO = extern struct {
    bmciHeader: BITMAPCOREHEADER,
    bmciColors: [1]RGBTRIPLE,
};
type
  BITMAPCOREHEADER {.bycopy.} = object
    bcSize: uint32
    bcWidth: uint16
    bcHeight: uint16
    bcPlanes: uint16
    bcBitCount: uint16

  RGBTRIPLE {.bycopy.} = object
    rgbtBlue: uint8
    rgbtGreen: uint8
    rgbtRed: uint8

  BITMAPCOREINFO {.bycopy.} = object
    bmciHeader: BITMAPCOREHEADER
    bmciColors: array[1, RGBTRIPLE]
struct BITMAPCOREHEADER
{
    uint bcSize;
    ushort bcWidth;
    ushort bcHeight;
    ushort bcPlanes;
    ushort bcBitCount;
}

struct RGBTRIPLE
{
    ubyte rgbtBlue;
    ubyte rgbtGreen;
    ubyte rgbtRed;
}

struct BITMAPCOREINFO
{
    BITMAPCOREHEADER bmciHeader;
    RGBTRIPLE[1] bmciColors;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; BITMAPCOREINFO サイズ: 16 バイト(x64)
dim st, 4    ; 4byte整数×4(構造体サイズ 16 / 4 切り上げ)
; bmciHeader : BITMAPCOREHEADER (+0, 12byte)  varptr(st)+0 を基点に操作(12byte:入れ子/配列)
; bmciColors : RGBTRIPLE (+12, 3byte)  varptr(st)+12 を基点に操作(3byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global BITMAPCOREHEADER
    #field int bcSize
    #field short bcWidth
    #field short bcHeight
    #field short bcPlanes
    #field short bcBitCount
#endstruct

#defstruct global RGBTRIPLE
    #field byte rgbtBlue
    #field byte rgbtGreen
    #field byte rgbtRed
#endstruct

#defstruct global BITMAPCOREINFO
    #field BITMAPCOREHEADER bmciHeader
    #field RGBTRIPLE bmciColors 1
#endstruct

stdim st, BITMAPCOREINFO        ; NSTRUCT 変数を確保