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

BitmapData

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

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

フィールド

フィールドサイズx64x86説明
WidthDWORD4+0+0ロックされたビットマップ領域の幅をピクセルで表す。
HeightDWORD4+4+4ロックされたビットマップ領域の高さをピクセルで表す。
StrideINT4+8+81走査線あたりのバイト数(ストライド)を表す。負値の場合あり。
PixelFormatINT4+12+12ピクセルフォーマットを表す。32bppARGB等。
Scan0void*8/4+16+16ロックされたピクセルデータの先頭アドレスへのポインタ。
ReservedUINT_PTR8/4+24+20システム予約フィールド。使用しない。

各言語での定義

#include <windows.h>

// BitmapData  (x64 32 / x86 24 バイト)
typedef struct BitmapData {
    DWORD Width;
    DWORD Height;
    INT Stride;
    INT PixelFormat;
    void* Scan0;
    UINT_PTR Reserved;
} BitmapData;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BitmapData
{
    public uint Width;
    public uint Height;
    public int Stride;
    public int PixelFormat;
    public IntPtr Scan0;
    public UIntPtr Reserved;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure BitmapData
    Public Width As UInteger
    Public Height As UInteger
    Public Stride As Integer
    Public PixelFormat As Integer
    Public Scan0 As IntPtr
    Public Reserved As UIntPtr
End Structure
import ctypes
from ctypes import wintypes

class BitmapData(ctypes.Structure):
    _fields_ = [
        ("Width", wintypes.DWORD),
        ("Height", wintypes.DWORD),
        ("Stride", ctypes.c_int),
        ("PixelFormat", ctypes.c_int),
        ("Scan0", ctypes.c_void_p),
        ("Reserved", ctypes.c_size_t),
    ]
#[repr(C)]
pub struct BitmapData {
    pub Width: u32,
    pub Height: u32,
    pub Stride: i32,
    pub PixelFormat: i32,
    pub Scan0: *mut core::ffi::c_void,
    pub Reserved: usize,
}
import "golang.org/x/sys/windows"

type BitmapData struct {
	Width uint32
	Height uint32
	Stride int32
	PixelFormat int32
	Scan0 uintptr
	Reserved uintptr
}
type
  BitmapData = record
    Width: DWORD;
    Height: DWORD;
    Stride: Integer;
    PixelFormat: Integer;
    Scan0: Pointer;
    Reserved: NativeUInt;
  end;
const BitmapData = extern struct {
    Width: u32,
    Height: u32,
    Stride: i32,
    PixelFormat: i32,
    Scan0: ?*anyopaque,
    Reserved: usize,
};
type
  BitmapData {.bycopy.} = object
    Width: uint32
    Height: uint32
    Stride: int32
    PixelFormat: int32
    Scan0: pointer
    Reserved: uint
struct BitmapData
{
    uint Width;
    uint Height;
    int Stride;
    int PixelFormat;
    void* Scan0;
    size_t Reserved;
}

HSP用 定義

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

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; BitmapData サイズ: 24 バイト(x86)
dim st, 6    ; 4byte整数×6(構造体サイズ 24 / 4 切り上げ)
; Width : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; Height : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; Stride : INT (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; PixelFormat : INT (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; Scan0 : void* (+16, 4byte)  st.4 = 値  /  値 = st.4   (lpoke/lpeek も可)
; Reserved : UINT_PTR (+20, 4byte)  st.5 = 値  /  値 = st.5   (lpoke/lpeek も可)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; BitmapData サイズ: 32 バイト(x64)
dim st, 8    ; 4byte整数×8(構造体サイズ 32 / 4 切り上げ)
; Width : DWORD (+0, 4byte)  st.0 = 値  /  値 = st.0   (lpoke/lpeek も可)
; Height : DWORD (+4, 4byte)  st.1 = 値  /  値 = st.1   (lpoke/lpeek も可)
; Stride : INT (+8, 4byte)  st.2 = 値  /  値 = st.2   (lpoke/lpeek も可)
; PixelFormat : INT (+12, 4byte)  st.3 = 値  /  値 = st.3   (lpoke/lpeek も可)
; Scan0 : void* (+16, 8byte)  qpoke st,16,値 / qpeek(st,16)  ※IronHSPのみ。3.7/3.8は lpoke st,16,下位 : lpoke st,20,上位
; Reserved : UINT_PTR (+24, 8byte)  qpoke st,24,値 / qpeek(st,24)  ※IronHSPのみ。3.7/3.8は lpoke st,24,下位 : lpoke st,28,上位
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
#defstruct global BitmapData
    #field int Width
    #field int Height
    #field int Stride
    #field int PixelFormat
    #field intptr Scan0
    #field intptr Reserved
#endstruct

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