ホーム › Graphics.Gdi › SetDIBColorTable
SetDIBColorTable
関数DIBセクションのカラーテーブルにRGB値を設定する。
シグネチャ
// GDI32.dll
#include <windows.h>
DWORD SetDIBColorTable(
HDC hdc,
DWORD iStart,
DWORD cEntries,
const RGBQUAD* prgbq
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | デバイスコンテキスト。DIB がこのデバイスコンテキストに選択されている必要があります。 |
| iStart | DWORD | in | 設定する最初のカラーテーブルエントリを指定する、0 から始まるカラーテーブルインデックス。 |
| cEntries | DWORD | in | 設定するカラーテーブルエントリの数。 |
| prgbq | RGBQUAD* | in | DIB のカラーテーブルに設定する新しい色情報を格納した RGBQUAD 構造体の配列へのポインター。 |
戻り値の型: DWORD
公式ドキュメント
SetDIBColorTable 関数は、指定されたデバイスコンテキストに現在選択されている DIB のカラーテーブル内の、ある範囲のエントリに RGB(赤、緑、青)の色値を設定します。
戻り値
関数が成功した場合、戻り値は関数が設定したカラーテーブルエントリの数です。
関数が失敗した場合、戻り値は 0 です。
解説(Remarks)
この関数は、1、4、または 8 bpp を使用する DIB のカラーテーブルを設定するために呼び出します。ビットマップに関連付けられたビットマップ情報ヘッダー構造体の BitCount メンバー。
BITMAPINFOHEADER 構造体は、ピクセルあたりのビット数を指定します。biBitCount の値が 8 より大きいデバイス非依存ビットマップにはカラーテーブルがありません。
ビットマップに関連付けられた BITMAPV5HEADER 構造体の bV5BitCount メンバーは、ピクセルあたりのビット数を指定します。bV5BitCount の値が 8 より大きいデバイス非依存ビットマップにはカラーテーブルがありません。
ICM: カラーマネジメントは実行されません。
出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
DWORD SetDIBColorTable(
HDC hdc,
DWORD iStart,
DWORD cEntries,
const RGBQUAD* prgbq
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern uint SetDIBColorTable(
IntPtr hdc, // HDC
uint iStart, // DWORD
uint cEntries, // DWORD
IntPtr prgbq // RGBQUAD*
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function SetDIBColorTable(
hdc As IntPtr, ' HDC
iStart As UInteger, ' DWORD
cEntries As UInteger, ' DWORD
prgbq As IntPtr ' RGBQUAD*
) As UInteger
End Function' hdc : HDC
' iStart : DWORD
' cEntries : DWORD
' prgbq : RGBQUAD*
Declare PtrSafe Function SetDIBColorTable Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal iStart As Long, _
ByVal cEntries As Long, _
ByVal prgbq As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
SetDIBColorTable = ctypes.windll.gdi32.SetDIBColorTable
SetDIBColorTable.restype = wintypes.DWORD
SetDIBColorTable.argtypes = [
wintypes.HANDLE, # hdc : HDC
wintypes.DWORD, # iStart : DWORD
wintypes.DWORD, # cEntries : DWORD
ctypes.c_void_p, # prgbq : RGBQUAD*
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
SetDIBColorTable = Fiddle::Function.new(
lib['SetDIBColorTable'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
-Fiddle::TYPE_INT, # iStart : DWORD
-Fiddle::TYPE_INT, # cEntries : DWORD
Fiddle::TYPE_VOIDP, # prgbq : RGBQUAD*
],
-Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn SetDIBColorTable(
hdc: *mut core::ffi::c_void, // HDC
iStart: u32, // DWORD
cEntries: u32, // DWORD
prgbq: *const RGBQUAD // RGBQUAD*
) -> u32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern uint SetDIBColorTable(IntPtr hdc, uint iStart, uint cEntries, IntPtr prgbq);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_SetDIBColorTable' -Namespace Win32 -PassThru
# $api::SetDIBColorTable(hdc, iStart, cEntries, prgbq)#uselib "GDI32.dll"
#func global SetDIBColorTable "SetDIBColorTable" sptr, sptr, sptr, sptr
; SetDIBColorTable hdc, iStart, cEntries, varptr(prgbq) ; 戻り値は stat
; hdc : HDC -> "sptr"
; iStart : DWORD -> "sptr"
; cEntries : DWORD -> "sptr"
; prgbq : RGBQUAD* -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "GDI32.dll" #cfunc global SetDIBColorTable "SetDIBColorTable" sptr, int, int, var ; res = SetDIBColorTable(hdc, iStart, cEntries, prgbq) ; hdc : HDC -> "sptr" ; iStart : DWORD -> "int" ; cEntries : DWORD -> "int" ; prgbq : RGBQUAD* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global SetDIBColorTable "SetDIBColorTable" sptr, int, int, sptr ; res = SetDIBColorTable(hdc, iStart, cEntries, varptr(prgbq)) ; hdc : HDC -> "sptr" ; iStart : DWORD -> "int" ; cEntries : DWORD -> "int" ; prgbq : RGBQUAD* -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; DWORD SetDIBColorTable(HDC hdc, DWORD iStart, DWORD cEntries, RGBQUAD* prgbq) #uselib "GDI32.dll" #cfunc global SetDIBColorTable "SetDIBColorTable" intptr, int, int, var ; res = SetDIBColorTable(hdc, iStart, cEntries, prgbq) ; hdc : HDC -> "intptr" ; iStart : DWORD -> "int" ; cEntries : DWORD -> "int" ; prgbq : RGBQUAD* -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; DWORD SetDIBColorTable(HDC hdc, DWORD iStart, DWORD cEntries, RGBQUAD* prgbq) #uselib "GDI32.dll" #cfunc global SetDIBColorTable "SetDIBColorTable" intptr, int, int, intptr ; res = SetDIBColorTable(hdc, iStart, cEntries, varptr(prgbq)) ; hdc : HDC -> "intptr" ; iStart : DWORD -> "int" ; cEntries : DWORD -> "int" ; prgbq : RGBQUAD* -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procSetDIBColorTable = gdi32.NewProc("SetDIBColorTable")
)
// hdc (HDC), iStart (DWORD), cEntries (DWORD), prgbq (RGBQUAD*)
r1, _, err := procSetDIBColorTable.Call(
uintptr(hdc),
uintptr(iStart),
uintptr(cEntries),
uintptr(prgbq),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // DWORDfunction SetDIBColorTable(
hdc: THandle; // HDC
iStart: DWORD; // DWORD
cEntries: DWORD; // DWORD
prgbq: Pointer // RGBQUAD*
): DWORD; stdcall;
external 'GDI32.dll' name 'SetDIBColorTable';result := DllCall("GDI32\SetDIBColorTable"
, "Ptr", hdc ; HDC
, "UInt", iStart ; DWORD
, "UInt", cEntries ; DWORD
, "Ptr", prgbq ; RGBQUAD*
, "UInt") ; return: DWORD●SetDIBColorTable(hdc, iStart, cEntries, prgbq) = DLL("GDI32.dll", "dword SetDIBColorTable(void*, dword, dword, void*)")
# 呼び出し: SetDIBColorTable(hdc, iStart, cEntries, prgbq)
# hdc : HDC -> "void*"
# iStart : DWORD -> "dword"
# cEntries : DWORD -> "dword"
# prgbq : RGBQUAD* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn SetDIBColorTable(
hdc: ?*anyopaque, // HDC
iStart: u32, // DWORD
cEntries: u32, // DWORD
prgbq: [*c]RGBQUAD // RGBQUAD*
) callconv(std.os.windows.WINAPI) u32;proc SetDIBColorTable(
hdc: pointer, # HDC
iStart: uint32, # DWORD
cEntries: uint32, # DWORD
prgbq: ptr RGBQUAD # RGBQUAD*
): uint32 {.importc: "SetDIBColorTable", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
uint SetDIBColorTable(
void* hdc, // HDC
uint iStart, // DWORD
uint cEntries, // DWORD
RGBQUAD* prgbq // RGBQUAD*
);ccall((:SetDIBColorTable, "GDI32.dll"), stdcall, UInt32,
(Ptr{Cvoid}, UInt32, UInt32, Ptr{RGBQUAD}),
hdc, iStart, cEntries, prgbq)
# hdc : HDC -> Ptr{Cvoid}
# iStart : DWORD -> UInt32
# cEntries : DWORD -> UInt32
# prgbq : RGBQUAD* -> Ptr{RGBQUAD}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
uint32_t SetDIBColorTable(
void* hdc,
uint32_t iStart,
uint32_t cEntries,
void* prgbq);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.SetDIBColorTable(hdc, iStart, cEntries, prgbq)
-- hdc : HDC
-- iStart : DWORD
-- cEntries : DWORD
-- prgbq : RGBQUAD*
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const SetDIBColorTable = lib.func('__stdcall', 'SetDIBColorTable', 'uint32_t', ['void *', 'uint32_t', 'uint32_t', 'void *']);
// SetDIBColorTable(hdc, iStart, cEntries, prgbq)
// hdc : HDC -> 'void *'
// iStart : DWORD -> 'uint32_t'
// cEntries : DWORD -> 'uint32_t'
// prgbq : RGBQUAD* -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
SetDIBColorTable: { parameters: ["pointer", "u32", "u32", "pointer"], result: "u32" },
});
// lib.symbols.SetDIBColorTable(hdc, iStart, cEntries, prgbq)
// hdc : HDC -> "pointer"
// iStart : DWORD -> "u32"
// cEntries : DWORD -> "u32"
// prgbq : RGBQUAD* -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
uint32_t SetDIBColorTable(
void* hdc,
uint32_t iStart,
uint32_t cEntries,
void* prgbq);
C, "GDI32.dll");
// $ffi->SetDIBColorTable(hdc, iStart, cEntries, prgbq);
// hdc : HDC
// iStart : DWORD
// cEntries : DWORD
// prgbq : RGBQUAD*
// 構造体/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 SetDIBColorTable(
Pointer hdc, // HDC
int iStart, // DWORD
int cEntries, // DWORD
Pointer prgbq // RGBQUAD*
);
}@[Link("gdi32")]
lib LibGDI32
fun SetDIBColorTable = SetDIBColorTable(
hdc : Void*, # HDC
iStart : UInt32, # DWORD
cEntries : UInt32, # DWORD
prgbq : RGBQUAD* # RGBQUAD*
) : UInt32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef SetDIBColorTableNative = Uint32 Function(Pointer<Void>, Uint32, Uint32, Pointer<Void>);
typedef SetDIBColorTableDart = int Function(Pointer<Void>, int, int, Pointer<Void>);
final SetDIBColorTable = DynamicLibrary.open('GDI32.dll')
.lookupFunction<SetDIBColorTableNative, SetDIBColorTableDart>('SetDIBColorTable');
// hdc : HDC -> Pointer<Void>
// iStart : DWORD -> Uint32
// cEntries : DWORD -> Uint32
// prgbq : RGBQUAD* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function SetDIBColorTable(
hdc: THandle; // HDC
iStart: DWORD; // DWORD
cEntries: DWORD; // DWORD
prgbq: Pointer // RGBQUAD*
): DWORD; stdcall;
external 'GDI32.dll' name 'SetDIBColorTable';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "SetDIBColorTable"
c_SetDIBColorTable :: Ptr () -> Word32 -> Word32 -> Ptr () -> IO Word32
-- hdc : HDC -> Ptr ()
-- iStart : DWORD -> Word32
-- cEntries : DWORD -> Word32
-- prgbq : RGBQUAD* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let setdibcolortable =
foreign "SetDIBColorTable"
((ptr void) @-> uint32_t @-> uint32_t @-> (ptr void) @-> returning uint32_t)
(* hdc : HDC -> (ptr void) *)
(* iStart : DWORD -> uint32_t *)
(* cEntries : DWORD -> uint32_t *)
(* prgbq : RGBQUAD* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("SetDIBColorTable" set-dibcolor-table :convention :stdcall) :uint32
(hdc :pointer) ; HDC
(i-start :uint32) ; DWORD
(c-entries :uint32) ; DWORD
(prgbq :pointer)) ; RGBQUAD*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $SetDIBColorTable = Win32::API::More->new('GDI32',
'DWORD SetDIBColorTable(HANDLE hdc, DWORD iStart, DWORD cEntries, LPVOID prgbq)');
# my $ret = $SetDIBColorTable->Call($hdc, $iStart, $cEntries, $prgbq);
# hdc : HDC -> HANDLE
# iStart : DWORD -> DWORD
# cEntries : DWORD -> DWORD
# prgbq : RGBQUAD* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
公式の関連項目
- s BITMAPINFOHEADER
- f CreateDIBSection — アプリが直接アクセス可能なメモリを持つDIBセクションを作成する。
- s DIBSECTION
- f GetDIBColorTable — DIBセクションのカラーテーブルからRGB値を取得する。
使用する型