ホーム › Graphics.Gdi › SetPixel
SetPixel
関数指定座標のピクセルを指定色で描画し、実際の色を返す。
シグネチャ
// GDI32.dll
#include <windows.h>
COLORREF SetPixel(
HDC hdc,
INT x,
INT y,
COLORREF color
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdc | HDC | in |
| x | INT | in |
| y | INT | in |
| color | COLORREF | in |
戻り値の型: COLORREF
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
COLORREF SetPixel(
HDC hdc,
INT x,
INT y,
COLORREF color
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern uint SetPixel(
IntPtr hdc, // HDC
int x, // INT
int y, // INT
uint color // COLORREF
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function SetPixel(
hdc As IntPtr, ' HDC
x As Integer, ' INT
y As Integer, ' INT
color As UInteger ' COLORREF
) As UInteger
End Function' hdc : HDC
' x : INT
' y : INT
' color : COLORREF
Declare PtrSafe Function SetPixel Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal x As Long, _
ByVal y As Long, _
ByVal color As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetPixel = ctypes.windll.gdi32.SetPixel
SetPixel.restype = wintypes.DWORD
SetPixel.argtypes = [
wintypes.HANDLE, # hdc : HDC
ctypes.c_int, # x : INT
ctypes.c_int, # y : INT
wintypes.DWORD, # color : COLORREF
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
SetPixel = Fiddle::Function.new(
lib['SetPixel'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_INT, # x : INT
Fiddle::TYPE_INT, # y : INT
-Fiddle::TYPE_INT, # color : COLORREF
],
-Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn SetPixel(
hdc: *mut core::ffi::c_void, // HDC
x: i32, // INT
y: i32, // INT
color: u32 // COLORREF
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern uint SetPixel(IntPtr hdc, int x, int y, uint color);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_SetPixel' -Namespace Win32 -PassThru
# $api::SetPixel(hdc, x, y, color)#uselib "GDI32.dll"
#func global SetPixel "SetPixel" sptr, sptr, sptr, sptr
; SetPixel hdc, x, y, color ; 戻り値は stat
; hdc : HDC -> "sptr"
; x : INT -> "sptr"
; y : INT -> "sptr"
; color : COLORREF -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll"
#cfunc global SetPixel "SetPixel" sptr, int, int, int
; res = SetPixel(hdc, x, y, color)
; hdc : HDC -> "sptr"
; x : INT -> "int"
; y : INT -> "int"
; color : COLORREF -> "int"; COLORREF SetPixel(HDC hdc, INT x, INT y, COLORREF color)
#uselib "GDI32.dll"
#cfunc global SetPixel "SetPixel" intptr, int, int, int
; res = SetPixel(hdc, x, y, color)
; hdc : HDC -> "intptr"
; x : INT -> "int"
; y : INT -> "int"
; color : COLORREF -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procSetPixel = gdi32.NewProc("SetPixel")
)
// hdc (HDC), x (INT), y (INT), color (COLORREF)
r1, _, err := procSetPixel.Call(
uintptr(hdc),
uintptr(x),
uintptr(y),
uintptr(color),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // COLORREFfunction SetPixel(
hdc: THandle; // HDC
x: Integer; // INT
y: Integer; // INT
color: DWORD // COLORREF
): DWORD; stdcall;
external 'GDI32.dll' name 'SetPixel';result := DllCall("GDI32\SetPixel"
, "Ptr", hdc ; HDC
, "Int", x ; INT
, "Int", y ; INT
, "UInt", color ; COLORREF
, "UInt") ; return: COLORREF●SetPixel(hdc, x, y, color) = DLL("GDI32.dll", "dword SetPixel(void*, int, int, dword)")
# 呼び出し: SetPixel(hdc, x, y, color)
# hdc : HDC -> "void*"
# x : INT -> "int"
# y : INT -> "int"
# color : COLORREF -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。