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

GdipBitmapLockBits

関数
ビットマップの指定領域をロックしてピクセルデータへの直接アクセスを得る。
DLLgdiplus.dll呼出規約winapi

シグネチャ

// gdiplus.dll
#include <windows.h>

Status GdipBitmapLockBits(
    GpBitmap* bitmap,
    const Rect* rect,
    DWORD flags,
    INT format,
    BitmapData* lockedBitmapData
);

パラメーター

名前方向
bitmapGpBitmap*inout
rectRect*in
flagsDWORDin
formatINTin
lockedBitmapDataBitmapData*inout

戻り値の型: Status

各言語での呼び出し定義

// gdiplus.dll
#include <windows.h>

Status GdipBitmapLockBits(
    GpBitmap* bitmap,
    const Rect* rect,
    DWORD flags,
    INT format,
    BitmapData* lockedBitmapData
);
[DllImport("gdiplus.dll", ExactSpelling = true)]
static extern int GdipBitmapLockBits(
    IntPtr bitmap,   // GpBitmap* in/out
    IntPtr rect,   // Rect*
    uint flags,   // DWORD
    int format,   // INT
    IntPtr lockedBitmapData   // BitmapData* in/out
);
<DllImport("gdiplus.dll", ExactSpelling:=True)>
Public Shared Function GdipBitmapLockBits(
    bitmap As IntPtr,   ' GpBitmap* in/out
    rect As IntPtr,   ' Rect*
    flags As UInteger,   ' DWORD
    format As Integer,   ' INT
    lockedBitmapData As IntPtr   ' BitmapData* in/out
) As Integer
End Function
' bitmap : GpBitmap* in/out
' rect : Rect*
' flags : DWORD
' format : INT
' lockedBitmapData : BitmapData* in/out
Declare PtrSafe Function GdipBitmapLockBits Lib "gdiplus" ( _
    ByVal bitmap As LongPtr, _
    ByVal rect As LongPtr, _
    ByVal flags As Long, _
    ByVal format As Long, _
    ByVal lockedBitmapData As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

GdipBitmapLockBits = ctypes.windll.gdiplus.GdipBitmapLockBits
GdipBitmapLockBits.restype = ctypes.c_int
GdipBitmapLockBits.argtypes = [
    ctypes.c_void_p,  # bitmap : GpBitmap* in/out
    ctypes.c_void_p,  # rect : Rect*
    wintypes.DWORD,  # flags : DWORD
    ctypes.c_int,  # format : INT
    ctypes.c_void_p,  # lockedBitmapData : BitmapData* in/out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('gdiplus.dll')
GdipBitmapLockBits = Fiddle::Function.new(
  lib['GdipBitmapLockBits'],
  [
    Fiddle::TYPE_VOIDP,  # bitmap : GpBitmap* in/out
    Fiddle::TYPE_VOIDP,  # rect : Rect*
    -Fiddle::TYPE_INT,  # flags : DWORD
    Fiddle::TYPE_INT,  # format : INT
    Fiddle::TYPE_VOIDP,  # lockedBitmapData : BitmapData* in/out
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdiplus")]
extern "system" {
    fn GdipBitmapLockBits(
        bitmap: *mut GpBitmap,  // GpBitmap* in/out
        rect: *const Rect,  // Rect*
        flags: u32,  // DWORD
        format: i32,  // INT
        lockedBitmapData: *mut BitmapData  // BitmapData* in/out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("gdiplus.dll")]
public static extern int GdipBitmapLockBits(IntPtr bitmap, IntPtr rect, uint flags, int format, IntPtr lockedBitmapData);
"@
$api = Add-Type -MemberDefinition $sig -Name 'gdiplus_GdipBitmapLockBits' -Namespace Win32 -PassThru
# $api::GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData)
#uselib "gdiplus.dll"
#func global GdipBitmapLockBits "GdipBitmapLockBits" sptr, sptr, sptr, sptr, sptr
; GdipBitmapLockBits varptr(bitmap), varptr(rect), flags, format, varptr(lockedBitmapData)   ; 戻り値は stat
; bitmap : GpBitmap* in/out -> "sptr"
; rect : Rect* -> "sptr"
; flags : DWORD -> "sptr"
; format : INT -> "sptr"
; lockedBitmapData : BitmapData* in/out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "gdiplus.dll"
#cfunc global GdipBitmapLockBits "GdipBitmapLockBits" var, var, int, int, var
; res = GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData)
; bitmap : GpBitmap* in/out -> "var"
; rect : Rect* -> "var"
; flags : DWORD -> "int"
; format : INT -> "int"
; lockedBitmapData : BitmapData* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; Status GdipBitmapLockBits(GpBitmap* bitmap, Rect* rect, DWORD flags, INT format, BitmapData* lockedBitmapData)
#uselib "gdiplus.dll"
#cfunc global GdipBitmapLockBits "GdipBitmapLockBits" var, var, int, int, var
; res = GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData)
; bitmap : GpBitmap* in/out -> "var"
; rect : Rect* -> "var"
; flags : DWORD -> "int"
; format : INT -> "int"
; lockedBitmapData : BitmapData* in/out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
	procGdipBitmapLockBits = gdiplus.NewProc("GdipBitmapLockBits")
)

// bitmap (GpBitmap* in/out), rect (Rect*), flags (DWORD), format (INT), lockedBitmapData (BitmapData* in/out)
r1, _, err := procGdipBitmapLockBits.Call(
	uintptr(bitmap),
	uintptr(rect),
	uintptr(flags),
	uintptr(format),
	uintptr(lockedBitmapData),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // Status
function GdipBitmapLockBits(
  bitmap: Pointer;   // GpBitmap* in/out
  rect: Pointer;   // Rect*
  flags: DWORD;   // DWORD
  format: Integer;   // INT
  lockedBitmapData: Pointer   // BitmapData* in/out
): Integer; stdcall;
  external 'gdiplus.dll' name 'GdipBitmapLockBits';
result := DllCall("gdiplus\GdipBitmapLockBits"
    , "Ptr", bitmap   ; GpBitmap* in/out
    , "Ptr", rect   ; Rect*
    , "UInt", flags   ; DWORD
    , "Int", format   ; INT
    , "Ptr", lockedBitmapData   ; BitmapData* in/out
    , "Int")   ; return: Status
●GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData) = DLL("gdiplus.dll", "int GdipBitmapLockBits(void*, void*, dword, int, void*)")
# 呼び出し: GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData)
# bitmap : GpBitmap* in/out -> "void*"
# rect : Rect* -> "void*"
# flags : DWORD -> "dword"
# format : INT -> "int"
# lockedBitmapData : BitmapData* in/out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。