ホーム › Graphics.GdiPlus › GdipBitmapGetPixel
GdipBitmapGetPixel
関数ビットマップの指定座標のピクセル色を取得する。
シグネチャ
// gdiplus.dll
#include <windows.h>
Status GdipBitmapGetPixel(
GpBitmap* bitmap,
INT x,
INT y,
DWORD* color
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| bitmap | GpBitmap* | inout | 対象のGpBitmapオブジェクトへのポインタ。 |
| x | INT | in | 取得するピクセルのX座標(0起点の整数)。 |
| y | INT | in | 取得するピクセルのY座標(0起点の整数)。 |
| color | DWORD* | inout | 取得した色をARGB形式で受け取る出力先DWORDポインタ。 |
戻り値の型: 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 方式にも切替可。#uselib "gdiplus.dll" #cfunc global GdipBitmapGetPixel "GdipBitmapGetPixel" sptr, int, int, sptr ; res = GdipBitmapGetPixel(varptr(bitmap), x, y, varptr(color)) ; bitmap : GpBitmap* in/out -> "sptr" ; x : INT -> "int" ; y : INT -> "int" ; color : DWORD* in/out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは 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 方式にも切替可。; Status GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y, DWORD* color) #uselib "gdiplus.dll" #cfunc global GdipBitmapGetPixel "GdipBitmapGetPixel" intptr, int, int, intptr ; res = GdipBitmapGetPixel(varptr(bitmap), x, y, varptr(color)) ; bitmap : GpBitmap* in/out -> "intptr" ; x : INT -> "int" ; y : INT -> "int" ; color : DWORD* in/out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは 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 // Statusfunction 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)。const std = @import("std");
extern "gdiplus" fn GdipBitmapGetPixel(
bitmap: [*c]GpBitmap, // GpBitmap* in/out
x: i32, // INT
y: i32, // INT
color: [*c]u32 // DWORD* in/out
) callconv(std.os.windows.WINAPI) i32;proc GdipBitmapGetPixel(
bitmap: ptr GpBitmap, # GpBitmap* in/out
x: int32, # INT
y: int32, # INT
color: ptr uint32 # DWORD* in/out
): int32 {.importc: "GdipBitmapGetPixel", stdcall, dynlib: "gdiplus.dll".}pragma(lib, "gdiplus");
extern(Windows)
int GdipBitmapGetPixel(
GpBitmap* bitmap, // GpBitmap* in/out
int x, // INT
int y, // INT
uint* color // DWORD* in/out
);ccall((:GdipBitmapGetPixel, "gdiplus.dll"), stdcall, Int32,
(Ptr{GpBitmap}, Int32, Int32, Ptr{UInt32}),
bitmap, x, y, color)
# bitmap : GpBitmap* in/out -> Ptr{GpBitmap}
# x : INT -> Int32
# y : INT -> Int32
# color : DWORD* in/out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GdipBitmapGetPixel(
void* bitmap,
int32_t x,
int32_t y,
uint32_t* color);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipBitmapGetPixel(bitmap, x, y, color)
-- bitmap : GpBitmap* in/out
-- x : INT
-- y : INT
-- color : DWORD* in/out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipBitmapGetPixel = lib.func('__stdcall', 'GdipBitmapGetPixel', 'int32_t', ['void *', 'int32_t', 'int32_t', 'uint32_t *']);
// GdipBitmapGetPixel(bitmap, x, y, color)
// bitmap : GpBitmap* in/out -> 'void *'
// x : INT -> 'int32_t'
// y : INT -> 'int32_t'
// color : DWORD* in/out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("gdiplus.dll", {
GdipBitmapGetPixel: { parameters: ["pointer", "i32", "i32", "pointer"], result: "i32" },
});
// lib.symbols.GdipBitmapGetPixel(bitmap, x, y, color)
// bitmap : GpBitmap* in/out -> "pointer"
// x : INT -> "i32"
// y : INT -> "i32"
// color : DWORD* in/out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GdipBitmapGetPixel(
void* bitmap,
int32_t x,
int32_t y,
uint32_t* color);
C, "gdiplus.dll");
// $ffi->GdipBitmapGetPixel(bitmap, x, y, color);
// bitmap : GpBitmap* in/out
// x : INT
// y : INT
// color : DWORD* 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 GdipBitmapGetPixel(
Pointer bitmap, // GpBitmap* in/out
int x, // INT
int y, // INT
IntByReference color // DWORD* in/out
);
}@[Link("gdiplus")]
lib Libgdiplus
fun GdipBitmapGetPixel = GdipBitmapGetPixel(
bitmap : GpBitmap*, # GpBitmap* in/out
x : Int32, # INT
y : Int32, # INT
color : UInt32* # DWORD* 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 GdipBitmapGetPixelNative = Int32 Function(Pointer<Void>, Int32, Int32, Pointer<Uint32>);
typedef GdipBitmapGetPixelDart = int Function(Pointer<Void>, int, int, Pointer<Uint32>);
final GdipBitmapGetPixel = DynamicLibrary.open('gdiplus.dll')
.lookupFunction<GdipBitmapGetPixelNative, GdipBitmapGetPixelDart>('GdipBitmapGetPixel');
// bitmap : GpBitmap* in/out -> Pointer<Void>
// x : INT -> Int32
// y : INT -> Int32
// color : DWORD* in/out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GdipBitmapGetPixel"
c_GdipBitmapGetPixel :: Ptr () -> Int32 -> Int32 -> Ptr Word32 -> IO Int32
-- bitmap : GpBitmap* in/out -> Ptr ()
-- x : INT -> Int32
-- y : INT -> Int32
-- color : DWORD* in/out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gdipbitmapgetpixel =
foreign "GdipBitmapGetPixel"
((ptr void) @-> int32_t @-> int32_t @-> (ptr uint32_t) @-> returning int32_t)
(* bitmap : GpBitmap* in/out -> (ptr void) *)
(* x : INT -> int32_t *)
(* y : INT -> int32_t *)
(* color : DWORD* in/out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdiplus (t "gdiplus.dll"))
(cffi:use-foreign-library gdiplus)
(cffi:defcfun ("GdipBitmapGetPixel" gdip-bitmap-get-pixel :convention :stdcall) :int32
(bitmap :pointer) ; GpBitmap* in/out
(x :int32) ; INT
(y :int32) ; INT
(color :pointer)) ; DWORD* in/out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GdipBitmapGetPixel = Win32::API::More->new('gdiplus',
'int GdipBitmapGetPixel(LPVOID bitmap, int x, int y, LPVOID color)');
# my $ret = $GdipBitmapGetPixel->Call($bitmap, $x, $y, $color);
# bitmap : GpBitmap* in/out -> LPVOID
# x : INT -> int
# y : INT -> int
# color : DWORD* in/out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型