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