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

SetDIBitsToDevice

関数
DIBのピクセルを直接デバイスの矩形領域へ転送する。
DLLGDI32.dll呼出規約winapi対応OSWindows 2000 以降

シグネチャ

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

INT SetDIBitsToDevice(
    HDC hdc,
    INT xDest,
    INT yDest,
    DWORD w,
    DWORD h,
    INT xSrc,
    INT ySrc,
    DWORD StartScan,
    DWORD cLines,
    const void* lpvBits,
    const BITMAPINFO* lpbmi,
    DIB_USAGE ColorUse
);

パラメーター

名前方向
hdcHDCin
xDestINTin
yDestINTin
wDWORDin
hDWORDin
xSrcINTin
ySrcINTin
StartScanDWORDin
cLinesDWORDin
lpvBitsvoid*in
lpbmiBITMAPINFO*in
ColorUseDIB_USAGEin

戻り値の型: INT

各言語での呼び出し定義

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

INT SetDIBitsToDevice(
    HDC hdc,
    INT xDest,
    INT yDest,
    DWORD w,
    DWORD h,
    INT xSrc,
    INT ySrc,
    DWORD StartScan,
    DWORD cLines,
    const void* lpvBits,
    const BITMAPINFO* lpbmi,
    DIB_USAGE ColorUse
);
[DllImport("GDI32.dll", ExactSpelling = true)]
static extern int SetDIBitsToDevice(
    IntPtr hdc,   // HDC
    int xDest,   // INT
    int yDest,   // INT
    uint w,   // DWORD
    uint h,   // DWORD
    int xSrc,   // INT
    int ySrc,   // INT
    uint StartScan,   // DWORD
    uint cLines,   // DWORD
    IntPtr lpvBits,   // void*
    IntPtr lpbmi,   // BITMAPINFO*
    uint ColorUse   // DIB_USAGE
);
<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function SetDIBitsToDevice(
    hdc As IntPtr,   ' HDC
    xDest As Integer,   ' INT
    yDest As Integer,   ' INT
    w As UInteger,   ' DWORD
    h As UInteger,   ' DWORD
    xSrc As Integer,   ' INT
    ySrc As Integer,   ' INT
    StartScan As UInteger,   ' DWORD
    cLines As UInteger,   ' DWORD
    lpvBits As IntPtr,   ' void*
    lpbmi As IntPtr,   ' BITMAPINFO*
    ColorUse As UInteger   ' DIB_USAGE
) As Integer
End Function
' hdc : HDC
' xDest : INT
' yDest : INT
' w : DWORD
' h : DWORD
' xSrc : INT
' ySrc : INT
' StartScan : DWORD
' cLines : DWORD
' lpvBits : void*
' lpbmi : BITMAPINFO*
' ColorUse : DIB_USAGE
Declare PtrSafe Function SetDIBitsToDevice Lib "gdi32" ( _
    ByVal hdc As LongPtr, _
    ByVal xDest As Long, _
    ByVal yDest As Long, _
    ByVal w As Long, _
    ByVal h As Long, _
    ByVal xSrc As Long, _
    ByVal ySrc As Long, _
    ByVal StartScan As Long, _
    ByVal cLines As Long, _
    ByVal lpvBits 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

SetDIBitsToDevice = ctypes.windll.gdi32.SetDIBitsToDevice
SetDIBitsToDevice.restype = ctypes.c_int
SetDIBitsToDevice.argtypes = [
    wintypes.HANDLE,  # hdc : HDC
    ctypes.c_int,  # xDest : INT
    ctypes.c_int,  # yDest : INT
    wintypes.DWORD,  # w : DWORD
    wintypes.DWORD,  # h : DWORD
    ctypes.c_int,  # xSrc : INT
    ctypes.c_int,  # ySrc : INT
    wintypes.DWORD,  # StartScan : DWORD
    wintypes.DWORD,  # cLines : DWORD
    ctypes.POINTER(None),  # lpvBits : void*
    ctypes.c_void_p,  # lpbmi : BITMAPINFO*
    wintypes.DWORD,  # ColorUse : DIB_USAGE
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('GDI32.dll')
SetDIBitsToDevice = Fiddle::Function.new(
  lib['SetDIBitsToDevice'],
  [
    Fiddle::TYPE_VOIDP,  # hdc : HDC
    Fiddle::TYPE_INT,  # xDest : INT
    Fiddle::TYPE_INT,  # yDest : INT
    -Fiddle::TYPE_INT,  # w : DWORD
    -Fiddle::TYPE_INT,  # h : DWORD
    Fiddle::TYPE_INT,  # xSrc : INT
    Fiddle::TYPE_INT,  # ySrc : INT
    -Fiddle::TYPE_INT,  # StartScan : DWORD
    -Fiddle::TYPE_INT,  # cLines : DWORD
    Fiddle::TYPE_VOIDP,  # lpvBits : void*
    Fiddle::TYPE_VOIDP,  # lpbmi : BITMAPINFO*
    -Fiddle::TYPE_INT,  # ColorUse : DIB_USAGE
  ],
  Fiddle::TYPE_INT)
#[link(name = "gdi32")]
extern "system" {
    fn SetDIBitsToDevice(
        hdc: *mut core::ffi::c_void,  // HDC
        xDest: i32,  // INT
        yDest: i32,  // INT
        w: u32,  // DWORD
        h: u32,  // DWORD
        xSrc: i32,  // INT
        ySrc: i32,  // INT
        StartScan: u32,  // DWORD
        cLines: u32,  // DWORD
        lpvBits: *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 SetDIBitsToDevice(IntPtr hdc, int xDest, int yDest, uint w, uint h, int xSrc, int ySrc, uint StartScan, uint cLines, IntPtr lpvBits, IntPtr lpbmi, uint ColorUse);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_SetDIBitsToDevice' -Namespace Win32 -PassThru
# $api::SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
#uselib "GDI32.dll"
#func global SetDIBitsToDevice "SetDIBitsToDevice" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; SetDIBitsToDevice hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, varptr(lpbmi), ColorUse   ; 戻り値は stat
; hdc : HDC -> "sptr"
; xDest : INT -> "sptr"
; yDest : INT -> "sptr"
; w : DWORD -> "sptr"
; h : DWORD -> "sptr"
; xSrc : INT -> "sptr"
; ySrc : INT -> "sptr"
; StartScan : DWORD -> "sptr"
; cLines : DWORD -> "sptr"
; lpvBits : void* -> "sptr"
; lpbmi : BITMAPINFO* -> "sptr"
; ColorUse : DIB_USAGE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "GDI32.dll"
#cfunc global SetDIBitsToDevice "SetDIBitsToDevice" sptr, int, int, int, int, int, int, int, int, sptr, var, int
; res = SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
; hdc : HDC -> "sptr"
; xDest : INT -> "int"
; yDest : INT -> "int"
; w : DWORD -> "int"
; h : DWORD -> "int"
; xSrc : INT -> "int"
; ySrc : INT -> "int"
; StartScan : DWORD -> "int"
; cLines : DWORD -> "int"
; lpvBits : void* -> "sptr"
; lpbmi : BITMAPINFO* -> "var"
; ColorUse : DIB_USAGE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; INT SetDIBitsToDevice(HDC hdc, INT xDest, INT yDest, DWORD w, DWORD h, INT xSrc, INT ySrc, DWORD StartScan, DWORD cLines, void* lpvBits, BITMAPINFO* lpbmi, DIB_USAGE ColorUse)
#uselib "GDI32.dll"
#cfunc global SetDIBitsToDevice "SetDIBitsToDevice" intptr, int, int, int, int, int, int, int, int, intptr, var, int
; res = SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
; hdc : HDC -> "intptr"
; xDest : INT -> "int"
; yDest : INT -> "int"
; w : DWORD -> "int"
; h : DWORD -> "int"
; xSrc : INT -> "int"
; ySrc : INT -> "int"
; StartScan : DWORD -> "int"
; cLines : DWORD -> "int"
; lpvBits : void* -> "intptr"
; lpbmi : BITMAPINFO* -> "var"
; ColorUse : DIB_USAGE -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	gdi32 = windows.NewLazySystemDLL("GDI32.dll")
	procSetDIBitsToDevice = gdi32.NewProc("SetDIBitsToDevice")
)

// hdc (HDC), xDest (INT), yDest (INT), w (DWORD), h (DWORD), xSrc (INT), ySrc (INT), StartScan (DWORD), cLines (DWORD), lpvBits (void*), lpbmi (BITMAPINFO*), ColorUse (DIB_USAGE)
r1, _, err := procSetDIBitsToDevice.Call(
	uintptr(hdc),
	uintptr(xDest),
	uintptr(yDest),
	uintptr(w),
	uintptr(h),
	uintptr(xSrc),
	uintptr(ySrc),
	uintptr(StartScan),
	uintptr(cLines),
	uintptr(lpvBits),
	uintptr(lpbmi),
	uintptr(ColorUse),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // INT
function SetDIBitsToDevice(
  hdc: THandle;   // HDC
  xDest: Integer;   // INT
  yDest: Integer;   // INT
  w: DWORD;   // DWORD
  h: DWORD;   // DWORD
  xSrc: Integer;   // INT
  ySrc: Integer;   // INT
  StartScan: DWORD;   // DWORD
  cLines: DWORD;   // DWORD
  lpvBits: Pointer;   // void*
  lpbmi: Pointer;   // BITMAPINFO*
  ColorUse: DWORD   // DIB_USAGE
): Integer; stdcall;
  external 'GDI32.dll' name 'SetDIBitsToDevice';
result := DllCall("GDI32\SetDIBitsToDevice"
    , "Ptr", hdc   ; HDC
    , "Int", xDest   ; INT
    , "Int", yDest   ; INT
    , "UInt", w   ; DWORD
    , "UInt", h   ; DWORD
    , "Int", xSrc   ; INT
    , "Int", ySrc   ; INT
    , "UInt", StartScan   ; DWORD
    , "UInt", cLines   ; DWORD
    , "Ptr", lpvBits   ; void*
    , "Ptr", lpbmi   ; BITMAPINFO*
    , "UInt", ColorUse   ; DIB_USAGE
    , "Int")   ; return: INT
●SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse) = DLL("GDI32.dll", "int SetDIBitsToDevice(void*, int, int, dword, dword, int, int, dword, dword, void*, void*, dword)")
# 呼び出し: SetDIBitsToDevice(hdc, xDest, yDest, w, h, xSrc, ySrc, StartScan, cLines, lpvBits, lpbmi, ColorUse)
# hdc : HDC -> "void*"
# xDest : INT -> "int"
# yDest : INT -> "int"
# w : DWORD -> "dword"
# h : DWORD -> "dword"
# xSrc : INT -> "int"
# ySrc : INT -> "int"
# StartScan : DWORD -> "dword"
# cLines : DWORD -> "dword"
# lpvBits : void* -> "void*"
# lpbmi : BITMAPINFO* -> "void*"
# ColorUse : DIB_USAGE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。