ホーム › Graphics.GdiPlus › GdipBitmapLockBits
GdipBitmapLockBits
関数ビットマップの指定領域をロックしてピクセルデータへの直接アクセスを得る。
シグネチャ
// gdiplus.dll
#include <windows.h>
Status GdipBitmapLockBits(
GpBitmap* bitmap,
const Rect* rect,
DWORD flags,
INT format,
BitmapData* lockedBitmapData
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| bitmap | GpBitmap* | inout | ロック対象のGpBitmapオブジェクトへのポインタ。 |
| rect | Rect* | in | ロックする矩形領域を示すRect構造体へのポインタ。NULLで全体を指す。 |
| flags | DWORD | in | アクセス方法を示すImageLockMode値(ReadOnly/WriteOnly/UserInputBuf等)。 |
| format | INT | in | ロック中に扱うピクセル形式を表すPixelFormat値。 |
| lockedBitmapData | BitmapData* | inout | ロック結果(ポインタやストライド)を受け取るBitmapData構造体へのポインタ。 |
戻り値の型: 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 方式にも切替可。#uselib "gdiplus.dll" #cfunc global GdipBitmapLockBits "GdipBitmapLockBits" sptr, sptr, int, int, sptr ; res = GdipBitmapLockBits(varptr(bitmap), varptr(rect), flags, format, varptr(lockedBitmapData)) ; bitmap : GpBitmap* in/out -> "sptr" ; rect : Rect* -> "sptr" ; flags : DWORD -> "int" ; format : INT -> "int" ; lockedBitmapData : BitmapData* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; Status GdipBitmapLockBits(GpBitmap* bitmap, Rect* rect, DWORD flags, INT format, BitmapData* lockedBitmapData) #uselib "gdiplus.dll" #cfunc global GdipBitmapLockBits "GdipBitmapLockBits" intptr, intptr, int, int, intptr ; res = GdipBitmapLockBits(varptr(bitmap), varptr(rect), flags, format, varptr(lockedBitmapData)) ; bitmap : GpBitmap* in/out -> "intptr" ; rect : Rect* -> "intptr" ; flags : DWORD -> "int" ; format : INT -> "int" ; lockedBitmapData : BitmapData* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // Statusfunction 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)。const std = @import("std");
extern "gdiplus" fn GdipBitmapLockBits(
bitmap: [*c]GpBitmap, // GpBitmap* in/out
rect: [*c]Rect, // Rect*
flags: u32, // DWORD
format: i32, // INT
lockedBitmapData: [*c]BitmapData // BitmapData* in/out
) callconv(std.os.windows.WINAPI) i32;proc GdipBitmapLockBits(
bitmap: ptr GpBitmap, # GpBitmap* in/out
rect: ptr Rect, # Rect*
flags: uint32, # DWORD
format: int32, # INT
lockedBitmapData: ptr BitmapData # BitmapData* in/out
): int32 {.importc: "GdipBitmapLockBits", stdcall, dynlib: "gdiplus.dll".}pragma(lib, "gdiplus");
extern(Windows)
int GdipBitmapLockBits(
GpBitmap* bitmap, // GpBitmap* in/out
Rect* rect, // Rect*
uint flags, // DWORD
int format, // INT
BitmapData* lockedBitmapData // BitmapData* in/out
);ccall((:GdipBitmapLockBits, "gdiplus.dll"), stdcall, Int32,
(Ptr{GpBitmap}, Ptr{Rect}, UInt32, Int32, Ptr{BitmapData}),
bitmap, rect, flags, format, lockedBitmapData)
# bitmap : GpBitmap* in/out -> Ptr{GpBitmap}
# rect : Rect* -> Ptr{Rect}
# flags : DWORD -> UInt32
# format : INT -> Int32
# lockedBitmapData : BitmapData* in/out -> Ptr{BitmapData}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GdipBitmapLockBits(
void* bitmap,
void* rect,
uint32_t flags,
int32_t format,
void* lockedBitmapData);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData)
-- bitmap : GpBitmap* in/out
-- rect : Rect*
-- flags : DWORD
-- format : INT
-- lockedBitmapData : BitmapData* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipBitmapLockBits = lib.func('__stdcall', 'GdipBitmapLockBits', 'int32_t', ['void *', 'void *', 'uint32_t', 'int32_t', 'void *']);
// GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData)
// bitmap : GpBitmap* in/out -> 'void *'
// rect : Rect* -> 'void *'
// flags : DWORD -> 'uint32_t'
// format : INT -> 'int32_t'
// lockedBitmapData : BitmapData* in/out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("gdiplus.dll", {
GdipBitmapLockBits: { parameters: ["pointer", "pointer", "u32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData)
// bitmap : GpBitmap* in/out -> "pointer"
// rect : Rect* -> "pointer"
// flags : DWORD -> "u32"
// format : INT -> "i32"
// lockedBitmapData : BitmapData* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GdipBitmapLockBits(
void* bitmap,
void* rect,
uint32_t flags,
int32_t format,
void* lockedBitmapData);
C, "gdiplus.dll");
// $ffi->GdipBitmapLockBits(bitmap, rect, flags, format, lockedBitmapData);
// bitmap : GpBitmap* in/out
// rect : Rect*
// flags : DWORD
// format : INT
// lockedBitmapData : BitmapData* in/out
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Gdiplus extends StdCallLibrary {
Gdiplus INSTANCE = Native.load("gdiplus", Gdiplus.class);
int GdipBitmapLockBits(
Pointer bitmap, // GpBitmap* in/out
Pointer rect, // Rect*
int flags, // DWORD
int format, // INT
Pointer lockedBitmapData // BitmapData* in/out
);
}@[Link("gdiplus")]
lib Libgdiplus
fun GdipBitmapLockBits = GdipBitmapLockBits(
bitmap : GpBitmap*, # GpBitmap* in/out
rect : Rect*, # Rect*
flags : UInt32, # DWORD
format : Int32, # INT
lockedBitmapData : BitmapData* # BitmapData* in/out
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GdipBitmapLockBitsNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Int32, Pointer<Void>);
typedef GdipBitmapLockBitsDart = int Function(Pointer<Void>, Pointer<Void>, int, int, Pointer<Void>);
final GdipBitmapLockBits = DynamicLibrary.open('gdiplus.dll')
.lookupFunction<GdipBitmapLockBitsNative, GdipBitmapLockBitsDart>('GdipBitmapLockBits');
// bitmap : GpBitmap* in/out -> Pointer<Void>
// rect : Rect* -> Pointer<Void>
// flags : DWORD -> Uint32
// format : INT -> Int32
// lockedBitmapData : BitmapData* in/out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GdipBitmapLockBits"
c_GdipBitmapLockBits :: Ptr () -> Ptr () -> Word32 -> Int32 -> Ptr () -> IO Int32
-- bitmap : GpBitmap* in/out -> Ptr ()
-- rect : Rect* -> Ptr ()
-- flags : DWORD -> Word32
-- format : INT -> Int32
-- lockedBitmapData : BitmapData* in/out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gdipbitmaplockbits =
foreign "GdipBitmapLockBits"
((ptr void) @-> (ptr void) @-> uint32_t @-> int32_t @-> (ptr void) @-> returning int32_t)
(* bitmap : GpBitmap* in/out -> (ptr void) *)
(* rect : Rect* -> (ptr void) *)
(* flags : DWORD -> uint32_t *)
(* format : INT -> int32_t *)
(* lockedBitmapData : BitmapData* in/out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdiplus (t "gdiplus.dll"))
(cffi:use-foreign-library gdiplus)
(cffi:defcfun ("GdipBitmapLockBits" gdip-bitmap-lock-bits :convention :stdcall) :int32
(bitmap :pointer) ; GpBitmap* in/out
(rect :pointer) ; Rect*
(flags :uint32) ; DWORD
(format :int32) ; INT
(locked-bitmap-data :pointer)) ; BitmapData* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GdipBitmapLockBits = Win32::API::More->new('gdiplus',
'int GdipBitmapLockBits(LPVOID bitmap, LPVOID rect, DWORD flags, int format, LPVOID lockedBitmapData)');
# my $ret = $GdipBitmapLockBits->Call($bitmap, $rect, $flags, $format, $lockedBitmapData);
# bitmap : GpBitmap* in/out -> LPVOID
# rect : Rect* -> LPVOID
# flags : DWORD -> DWORD
# format : INT -> int
# lockedBitmapData : BitmapData* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。