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

GdipBitmapGetPixel

関数
ビットマップの指定座標のピクセル色を取得する。
DLLgdiplus.dll呼出規約winapi

シグネチャ

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

Status GdipBitmapGetPixel(
    GpBitmap* bitmap,
    INT x,
    INT y,
    DWORD* color
);

パラメーター

名前方向
bitmapGpBitmap*inout
xINTin
yINTin
colorDWORD*inout

戻り値の型: Status

各言語での呼び出し定義

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

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

GdipBitmapGetPixel = ctypes.windll.gdiplus.GdipBitmapGetPixel
GdipBitmapGetPixel.restype = ctypes.c_int
GdipBitmapGetPixel.argtypes = [
    ctypes.c_void_p,  # bitmap : GpBitmap* in/out
    ctypes.c_int,  # x : INT
    ctypes.c_int,  # y : INT
    ctypes.POINTER(wintypes.DWORD),  # color : DWORD* in/out
]
require 'fiddle'
require 'fiddle/import'

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

var (
	gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
	procGdipBitmapGetPixel = gdiplus.NewProc("GdipBitmapGetPixel")
)

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