ホーム › Graphics.Gdi › SetDIBits
SetDIBits
関数DIBのビットでビットマップのピクセルを設定する。
シグネチャ
// GDI32.dll
#include <windows.h>
INT SetDIBits(
HDC hdc, // optional
HBITMAP hbm,
DWORD start,
DWORD cLines,
const void* lpBits,
const BITMAPINFO* lpbmi,
DIB_USAGE ColorUse
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hdc | HDC | inoptional |
| hbm | HBITMAP | in |
| start | DWORD | in |
| cLines | DWORD | in |
| lpBits | void* | in |
| lpbmi | BITMAPINFO* | in |
| ColorUse | DIB_USAGE | in |
戻り値の型: INT
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
INT SetDIBits(
HDC hdc, // optional
HBITMAP hbm,
DWORD start,
DWORD cLines,
const void* lpBits,
const BITMAPINFO* lpbmi,
DIB_USAGE ColorUse
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern int SetDIBits(
IntPtr hdc, // HDC optional
IntPtr hbm, // HBITMAP
uint start, // DWORD
uint cLines, // DWORD
IntPtr lpBits, // void*
IntPtr lpbmi, // BITMAPINFO*
uint ColorUse // DIB_USAGE
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function SetDIBits(
hdc As IntPtr, ' HDC optional
hbm As IntPtr, ' HBITMAP
start As UInteger, ' DWORD
cLines As UInteger, ' DWORD
lpBits As IntPtr, ' void*
lpbmi As IntPtr, ' BITMAPINFO*
ColorUse As UInteger ' DIB_USAGE
) As Integer
End Function' hdc : HDC optional
' hbm : HBITMAP
' start : DWORD
' cLines : DWORD
' lpBits : void*
' lpbmi : BITMAPINFO*
' ColorUse : DIB_USAGE
Declare PtrSafe Function SetDIBits Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal hbm As LongPtr, _
ByVal start As Long, _
ByVal cLines As Long, _
ByVal lpBits As LongPtr, _
ByVal lpbmi As LongPtr, _
ByVal ColorUse As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetDIBits = ctypes.windll.gdi32.SetDIBits
SetDIBits.restype = ctypes.c_int
SetDIBits.argtypes = [
wintypes.HANDLE, # hdc : HDC optional
wintypes.HANDLE, # hbm : HBITMAP
wintypes.DWORD, # start : DWORD
wintypes.DWORD, # cLines : DWORD
ctypes.POINTER(None), # lpBits : void*
ctypes.c_void_p, # lpbmi : BITMAPINFO*
wintypes.DWORD, # ColorUse : DIB_USAGE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
SetDIBits = Fiddle::Function.new(
lib['SetDIBits'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC optional
Fiddle::TYPE_VOIDP, # hbm : HBITMAP
-Fiddle::TYPE_INT, # start : DWORD
-Fiddle::TYPE_INT, # cLines : DWORD
Fiddle::TYPE_VOIDP, # lpBits : void*
Fiddle::TYPE_VOIDP, # lpbmi : BITMAPINFO*
-Fiddle::TYPE_INT, # ColorUse : DIB_USAGE
],
Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn SetDIBits(
hdc: *mut core::ffi::c_void, // HDC optional
hbm: *mut core::ffi::c_void, // HBITMAP
start: u32, // DWORD
cLines: u32, // DWORD
lpBits: *const (), // void*
lpbmi: *const BITMAPINFO, // BITMAPINFO*
ColorUse: u32 // DIB_USAGE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern int SetDIBits(IntPtr hdc, IntPtr hbm, uint start, uint cLines, IntPtr lpBits, IntPtr lpbmi, uint ColorUse);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_SetDIBits' -Namespace Win32 -PassThru
# $api::SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse)#uselib "GDI32.dll"
#func global SetDIBits "SetDIBits" sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetDIBits hdc, hbm, start, cLines, lpBits, varptr(lpbmi), ColorUse ; 戻り値は stat
; hdc : HDC optional -> "sptr"
; hbm : HBITMAP -> "sptr"
; start : DWORD -> "sptr"
; cLines : DWORD -> "sptr"
; lpBits : void* -> "sptr"
; lpbmi : BITMAPINFO* -> "sptr"
; ColorUse : DIB_USAGE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "GDI32.dll" #cfunc global SetDIBits "SetDIBits" sptr, sptr, int, int, sptr, var, int ; res = SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse) ; hdc : HDC optional -> "sptr" ; hbm : HBITMAP -> "sptr" ; start : DWORD -> "int" ; cLines : DWORD -> "int" ; lpBits : void* -> "sptr" ; lpbmi : BITMAPINFO* -> "var" ; ColorUse : DIB_USAGE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global SetDIBits "SetDIBits" sptr, sptr, int, int, sptr, sptr, int ; res = SetDIBits(hdc, hbm, start, cLines, lpBits, varptr(lpbmi), ColorUse) ; hdc : HDC optional -> "sptr" ; hbm : HBITMAP -> "sptr" ; start : DWORD -> "int" ; cLines : DWORD -> "int" ; lpBits : void* -> "sptr" ; lpbmi : BITMAPINFO* -> "sptr" ; ColorUse : DIB_USAGE -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; INT SetDIBits(HDC hdc, HBITMAP hbm, DWORD start, DWORD cLines, void* lpBits, BITMAPINFO* lpbmi, DIB_USAGE ColorUse) #uselib "GDI32.dll" #cfunc global SetDIBits "SetDIBits" intptr, intptr, int, int, intptr, var, int ; res = SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse) ; hdc : HDC optional -> "intptr" ; hbm : HBITMAP -> "intptr" ; start : DWORD -> "int" ; cLines : DWORD -> "int" ; lpBits : void* -> "intptr" ; lpbmi : BITMAPINFO* -> "var" ; ColorUse : DIB_USAGE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT SetDIBits(HDC hdc, HBITMAP hbm, DWORD start, DWORD cLines, void* lpBits, BITMAPINFO* lpbmi, DIB_USAGE ColorUse) #uselib "GDI32.dll" #cfunc global SetDIBits "SetDIBits" intptr, intptr, int, int, intptr, intptr, int ; res = SetDIBits(hdc, hbm, start, cLines, lpBits, varptr(lpbmi), ColorUse) ; hdc : HDC optional -> "intptr" ; hbm : HBITMAP -> "intptr" ; start : DWORD -> "int" ; cLines : DWORD -> "int" ; lpBits : void* -> "intptr" ; lpbmi : BITMAPINFO* -> "intptr" ; ColorUse : DIB_USAGE -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procSetDIBits = gdi32.NewProc("SetDIBits")
)
// hdc (HDC optional), hbm (HBITMAP), start (DWORD), cLines (DWORD), lpBits (void*), lpbmi (BITMAPINFO*), ColorUse (DIB_USAGE)
r1, _, err := procSetDIBits.Call(
uintptr(hdc),
uintptr(hbm),
uintptr(start),
uintptr(cLines),
uintptr(lpBits),
uintptr(lpbmi),
uintptr(ColorUse),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction SetDIBits(
hdc: THandle; // HDC optional
hbm: THandle; // HBITMAP
start: DWORD; // DWORD
cLines: DWORD; // DWORD
lpBits: Pointer; // void*
lpbmi: Pointer; // BITMAPINFO*
ColorUse: DWORD // DIB_USAGE
): Integer; stdcall;
external 'GDI32.dll' name 'SetDIBits';result := DllCall("GDI32\SetDIBits"
, "Ptr", hdc ; HDC optional
, "Ptr", hbm ; HBITMAP
, "UInt", start ; DWORD
, "UInt", cLines ; DWORD
, "Ptr", lpBits ; void*
, "Ptr", lpbmi ; BITMAPINFO*
, "UInt", ColorUse ; DIB_USAGE
, "Int") ; return: INT●SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse) = DLL("GDI32.dll", "int SetDIBits(void*, void*, dword, dword, void*, void*, dword)")
# 呼び出し: SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse)
# hdc : HDC optional -> "void*"
# hbm : HBITMAP -> "void*"
# start : DWORD -> "dword"
# cLines : DWORD -> "dword"
# lpBits : void* -> "void*"
# lpbmi : BITMAPINFO* -> "void*"
# ColorUse : DIB_USAGE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。