SetDIBits
関数シグネチャ
// 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 | 指定された DIB の色データを使用して変更される互換ビットマップ (DDB) へのハンドル。 | ||||||
| start | DWORD | in | lpvBits パラメーターが指す配列内の、デバイス非依存の色データの開始走査線。 | ||||||
| cLines | DWORD | in | デバイス非依存の色データを含む配列内の走査線の数。 | ||||||
| lpBits | void* | in | バイトの配列として格納された DIB 色データへのポインター。ビットマップ値の形式は、lpbmi パラメーターが指す BITMAPINFO 構造体の biBitCount メンバーによって異なります。 | ||||||
| lpbmi | BITMAPINFO* | in | DIB に関する情報を含む BITMAPINFO 構造体へのポインター。 | ||||||
| ColorUse | DIB_USAGE | in | BITMAPINFO 構造体の bmiColors メンバーが提供されているかどうか、提供されている場合は bmiColors が明示的な赤、緑、青 (RGB) の値を含むか、それともパレットインデックスを含むかを示します。fuColorUse パラメーターは、次のいずれかの値である必要があります。
|
戻り値の型: INT
公式ドキュメント
SetDIBits 関数は、指定された DIB に含まれる色データを使用して、互換ビットマップ (DDB) 内のピクセルを設定します。
戻り値
関数が成功した場合、戻り値はコピーされた走査線の数です。
関数が失敗した場合、戻り値はゼロです。
次の値が返される場合があります。
| 戻りコード | 説明 |
|---|---|
| 1 つ以上の入力パラメーターが無効です。 |
解説(Remarks)
ビットマップのビットがシステムパレットへのインデックスである場合に、最適なビットマップ描画速度が得られます。
アプリケーションは、GetSystemPaletteEntries 関数を呼び出すことで、システムパレットの色とインデックスを取得できます。色とインデックスを取得した後、アプリケーションは DIB を作成できます。詳細については、System Palette を参照してください。
hdc パラメーターで識別されるデバイスコンテキストは、fuColorUse パラメーターに DIB_PAL_COLORS 定数が設定されている場合にのみ使用され、それ以外の場合は無視されます。
hbmp パラメーターで識別されるビットマップは、アプリケーションがこの関数を呼び出すときに、デバイスコンテキストに選択されていてはなりません。
走査線は、RLE 圧縮ビットマップを除き、DWORD 境界に揃えられている必要があります。
ボトムアップ DIB の原点はビットマップの左下隅であり、トップダウン DIB の原点はビットマップの左上隅です。
ICM: SetICMMode を iEnableICM パラメーターを ICM_ON に設定して呼び出すことでカラーマネジメントが有効にされている場合、カラーマネジメントが実行されます。lpbmi で指定されたビットマップが、gamma および endpoints メンバーを指定する BITMAPV4HEADER を持つ場合、または gamma および endpoints メンバーか profileData および profileSize メンバーのいずれかを指定する BITMAPV5HEADER を持つ場合、この呼び出しはビットマップのピクセルを、デバイスコンテキストのソースカラースペースではなく、それらのメンバーで記述されたカラースペースで表現されているものとして扱います。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// 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)。const std = @import("std");
extern "gdi32" fn SetDIBits(
hdc: ?*anyopaque, // HDC optional
hbm: ?*anyopaque, // HBITMAP
start: u32, // DWORD
cLines: u32, // DWORD
lpBits: ?*anyopaque, // void*
lpbmi: [*c]BITMAPINFO, // BITMAPINFO*
ColorUse: u32 // DIB_USAGE
) callconv(std.os.windows.WINAPI) i32;proc SetDIBits(
hdc: pointer, # HDC optional
hbm: pointer, # HBITMAP
start: uint32, # DWORD
cLines: uint32, # DWORD
lpBits: pointer, # void*
lpbmi: ptr BITMAPINFO, # BITMAPINFO*
ColorUse: uint32 # DIB_USAGE
): int32 {.importc: "SetDIBits", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int SetDIBits(
void* hdc, // HDC optional
void* hbm, // HBITMAP
uint start, // DWORD
uint cLines, // DWORD
void* lpBits, // void*
BITMAPINFO* lpbmi, // BITMAPINFO*
uint ColorUse // DIB_USAGE
);ccall((:SetDIBits, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, UInt32, UInt32, Ptr{Cvoid}, Ptr{BITMAPINFO}, UInt32),
hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse)
# hdc : HDC optional -> Ptr{Cvoid}
# hbm : HBITMAP -> Ptr{Cvoid}
# start : DWORD -> UInt32
# cLines : DWORD -> UInt32
# lpBits : void* -> Ptr{Cvoid}
# lpbmi : BITMAPINFO* -> Ptr{BITMAPINFO}
# ColorUse : DIB_USAGE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t SetDIBits(
void* hdc,
void* hbm,
uint32_t start,
uint32_t cLines,
void* lpBits,
void* lpbmi,
uint32_t ColorUse);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse)
-- hdc : HDC optional
-- hbm : HBITMAP
-- start : DWORD
-- cLines : DWORD
-- lpBits : void*
-- lpbmi : BITMAPINFO*
-- ColorUse : DIB_USAGE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const SetDIBits = lib.func('__stdcall', 'SetDIBits', 'int32_t', ['void *', 'void *', 'uint32_t', 'uint32_t', 'void *', 'void *', 'uint32_t']);
// SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse)
// hdc : HDC optional -> 'void *'
// hbm : HBITMAP -> 'void *'
// start : DWORD -> 'uint32_t'
// cLines : DWORD -> 'uint32_t'
// lpBits : void* -> 'void *'
// lpbmi : BITMAPINFO* -> 'void *'
// ColorUse : DIB_USAGE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
SetDIBits: { parameters: ["pointer", "pointer", "u32", "u32", "pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse)
// hdc : HDC optional -> "pointer"
// hbm : HBITMAP -> "pointer"
// start : DWORD -> "u32"
// cLines : DWORD -> "u32"
// lpBits : void* -> "pointer"
// lpbmi : BITMAPINFO* -> "pointer"
// ColorUse : DIB_USAGE -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t SetDIBits(
void* hdc,
void* hbm,
uint32_t start,
uint32_t cLines,
void* lpBits,
void* lpbmi,
uint32_t ColorUse);
C, "GDI32.dll");
// $ffi->SetDIBits(hdc, hbm, start, cLines, lpBits, lpbmi, ColorUse);
// hdc : HDC optional
// hbm : HBITMAP
// start : DWORD
// cLines : DWORD
// lpBits : void*
// lpbmi : BITMAPINFO*
// ColorUse : DIB_USAGE
// 構造体/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 Gdi32 extends StdCallLibrary {
Gdi32 INSTANCE = Native.load("gdi32", Gdi32.class);
int SetDIBits(
Pointer hdc, // HDC optional
Pointer hbm, // HBITMAP
int start, // DWORD
int cLines, // DWORD
Pointer lpBits, // void*
Pointer lpbmi, // BITMAPINFO*
int ColorUse // DIB_USAGE
);
}@[Link("gdi32")]
lib LibGDI32
fun SetDIBits = SetDIBits(
hdc : Void*, # HDC optional
hbm : Void*, # HBITMAP
start : UInt32, # DWORD
cLines : UInt32, # DWORD
lpBits : Void*, # void*
lpbmi : BITMAPINFO*, # BITMAPINFO*
ColorUse : UInt32 # DIB_USAGE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetDIBitsNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32, Uint32, Pointer<Void>, Pointer<Void>, Uint32);
typedef SetDIBitsDart = int Function(Pointer<Void>, Pointer<Void>, int, int, Pointer<Void>, Pointer<Void>, int);
final SetDIBits = DynamicLibrary.open('GDI32.dll')
.lookupFunction<SetDIBitsNative, SetDIBitsDart>('SetDIBits');
// hdc : HDC optional -> Pointer<Void>
// hbm : HBITMAP -> Pointer<Void>
// start : DWORD -> Uint32
// cLines : DWORD -> Uint32
// lpBits : void* -> Pointer<Void>
// lpbmi : BITMAPINFO* -> Pointer<Void>
// ColorUse : DIB_USAGE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function 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';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetDIBits"
c_SetDIBits :: Ptr () -> Ptr () -> Word32 -> Word32 -> Ptr () -> Ptr () -> Word32 -> IO Int32
-- hdc : HDC optional -> Ptr ()
-- hbm : HBITMAP -> Ptr ()
-- start : DWORD -> Word32
-- cLines : DWORD -> Word32
-- lpBits : void* -> Ptr ()
-- lpbmi : BITMAPINFO* -> Ptr ()
-- ColorUse : DIB_USAGE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setdibits =
foreign "SetDIBits"
((ptr void) @-> (ptr void) @-> uint32_t @-> uint32_t @-> (ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* hdc : HDC optional -> (ptr void) *)
(* hbm : HBITMAP -> (ptr void) *)
(* start : DWORD -> uint32_t *)
(* cLines : DWORD -> uint32_t *)
(* lpBits : void* -> (ptr void) *)
(* lpbmi : BITMAPINFO* -> (ptr void) *)
(* ColorUse : DIB_USAGE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("SetDIBits" set-dibits :convention :stdcall) :int32
(hdc :pointer) ; HDC optional
(hbm :pointer) ; HBITMAP
(start :uint32) ; DWORD
(c-lines :uint32) ; DWORD
(lp-bits :pointer) ; void*
(lpbmi :pointer) ; BITMAPINFO*
(color-use :uint32)) ; DIB_USAGE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetDIBits = Win32::API::More->new('GDI32',
'int SetDIBits(HANDLE hdc, HANDLE hbm, DWORD start, DWORD cLines, LPVOID lpBits, LPVOID lpbmi, DWORD ColorUse)');
# my $ret = $SetDIBits->Call($hdc, $hbm, $start, $cLines, $lpBits, $lpbmi, $ColorUse);
# hdc : HDC optional -> HANDLE
# hbm : HBITMAP -> HANDLE
# start : DWORD -> DWORD
# cLines : DWORD -> DWORD
# lpBits : void* -> LPVOID
# lpbmi : BITMAPINFO* -> LPVOID
# ColorUse : DIB_USAGE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetDIBits — ビットマップのビットをDIB形式で取得する。
- f GetSystemPaletteEntries — システムパレットのエントリを取得する。