BitBlt
関数シグネチャ
// GDI32.dll
#include <windows.h>
BOOL BitBlt(
HDC hdc,
INT x,
INT y,
INT cx,
INT cy,
HDC hdcSrc, // optional
INT x1,
INT y1,
ROP_CODE rop
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hdc | HDC | in | デスティネーションデバイスコンテキストへのハンドル。 |
| x | INT | in | デスティネーション矩形の左上隅の x 座標 (論理単位)。 |
| y | INT | in | デスティネーション矩形の左上隅の y 座標 (論理単位)。 |
| cx | INT | in | ソース矩形およびデスティネーション矩形の幅 (論理単位)。 |
| cy | INT | in | ソース矩形およびデスティネーション矩形の高さ (論理単位)。 |
| hdcSrc | HDC | inoptional | ソースデバイスコンテキストへのハンドル。 |
| x1 | INT | in | ソース矩形の左上隅の x 座標 (論理単位)。 |
| y1 | INT | in | ソース矩形の左上隅の y 座標 (論理単位)。 |
| rop | ROP_CODE | in | ラスター操作コード。これらのコードは、最終的な色を得るために、ソース矩形の色データをデスティネーション矩形の色データとどのように組み合わせるかを定義します。 次の一覧に、代表的なラスター操作コードを示します。 |
戻り値の型: BOOL
公式ドキュメント
BitBlt 関数は、指定したソースデバイスコンテキストからピクセルの矩形に対応する色データを、ビットブロック転送 (bit-block transfer) によってデスティネーションデバイスコンテキストへ転送します。
戻り値
関数が成功した場合、戻り値は 0 以外の値です。
関数が失敗した場合、戻り値は 0 です。拡張エラー情報を取得するには、GetLastError を呼び出してください。
解説(Remarks)
BitBlt はデスティネーション DC に対してのみクリッピングを行います。
ソースデバイスコンテキストに回転またはせん断 (shear) 変換が適用されている場合、BitBlt はエラーを返します。ソースデバイスコンテキストにその他の変換が適用されている (かつ、対応する変換がデスティネーションデバイスコンテキストに適用されていない) 場合、デスティネーションデバイスコンテキスト内の矩形は、必要に応じて拡大、縮小、または回転されます。
ソースデバイスコンテキストとデスティネーションデバイスコンテキストの色形式が一致しない場合、BitBlt 関数はソースの色形式をデスティネーションの形式に合わせて変換します。
拡張メタファイルの記録中に、ソースデバイスコンテキストが拡張メタファイルデバイスコンテキストを指定している場合は、エラーが発生します。
すべてのデバイスが BitBlt 関数をサポートしているわけではありません。詳細については、GetDeviceCaps 関数の RC_BITBLT ラスター機能エントリ、および次の各関数を参照してください: MaskBlt、PlgBlt、StretchBlt。
ソースデバイスコンテキストとデスティネーションデバイスコンテキストが異なるデバイスを表している場合、BitBlt はエラーを返します。異なるデバイスの DC 間でデータを転送するには、GetDIBits を呼び出してメモリビットマップを DIB に変換します。その DIB を 2 番目のデバイスに表示するには、SetDIBits または StretchDIBits を呼び出します。
ICM: ブリット (blit) 時にはカラーマネジメントは行われません。
例
次のコード例は、BitBlt の使用方法を示しています。
if (!BitBlt(hdcMemDC,
0, 0,
rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
hdcWindow,
0, 0,
SRCCOPY))
{
MessageBox(hWnd, L"BitBlt has failed", L"Failed", MB_OK);
goto done;
}
この例を実際の文脈の中で確認するには、Capturing an Image を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
BOOL BitBlt(
HDC hdc,
INT x,
INT y,
INT cx,
INT cy,
HDC hdcSrc, // optional
INT x1,
INT y1,
ROP_CODE rop
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool BitBlt(
IntPtr hdc, // HDC
int x, // INT
int y, // INT
int cx, // INT
int cy, // INT
IntPtr hdcSrc, // HDC optional
int x1, // INT
int y1, // INT
uint rop // ROP_CODE
);<DllImport("GDI32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function BitBlt(
hdc As IntPtr, ' HDC
x As Integer, ' INT
y As Integer, ' INT
cx As Integer, ' INT
cy As Integer, ' INT
hdcSrc As IntPtr, ' HDC optional
x1 As Integer, ' INT
y1 As Integer, ' INT
rop As UInteger ' ROP_CODE
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' hdc : HDC
' x : INT
' y : INT
' cx : INT
' cy : INT
' hdcSrc : HDC optional
' x1 : INT
' y1 : INT
' rop : ROP_CODE
Declare PtrSafe Function BitBlt Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal hdcSrc As LongPtr, _
ByVal x1 As Long, _
ByVal y1 As Long, _
ByVal rop As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
BitBlt = ctypes.windll.gdi32.BitBlt
BitBlt.restype = wintypes.BOOL
BitBlt.argtypes = [
wintypes.HANDLE, # hdc : HDC
ctypes.c_int, # x : INT
ctypes.c_int, # y : INT
ctypes.c_int, # cx : INT
ctypes.c_int, # cy : INT
wintypes.HANDLE, # hdcSrc : HDC optional
ctypes.c_int, # x1 : INT
ctypes.c_int, # y1 : INT
wintypes.DWORD, # rop : ROP_CODE
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
BitBlt = Fiddle::Function.new(
lib['BitBlt'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_INT, # x : INT
Fiddle::TYPE_INT, # y : INT
Fiddle::TYPE_INT, # cx : INT
Fiddle::TYPE_INT, # cy : INT
Fiddle::TYPE_VOIDP, # hdcSrc : HDC optional
Fiddle::TYPE_INT, # x1 : INT
Fiddle::TYPE_INT, # y1 : INT
-Fiddle::TYPE_INT, # rop : ROP_CODE
],
Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn BitBlt(
hdc: *mut core::ffi::c_void, // HDC
x: i32, // INT
y: i32, // INT
cx: i32, // INT
cy: i32, // INT
hdcSrc: *mut core::ffi::c_void, // HDC optional
x1: i32, // INT
y1: i32, // INT
rop: u32 // ROP_CODE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("GDI32.dll", SetLastError = true)]
public static extern bool BitBlt(IntPtr hdc, int x, int y, int cx, int cy, IntPtr hdcSrc, int x1, int y1, uint rop);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_BitBlt' -Namespace Win32 -PassThru
# $api::BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)#uselib "GDI32.dll"
#func global BitBlt "BitBlt" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; BitBlt hdc, x, y, cx, cy, hdcSrc, x1, y1, rop ; 戻り値は stat
; hdc : HDC -> "sptr"
; x : INT -> "sptr"
; y : INT -> "sptr"
; cx : INT -> "sptr"
; cy : INT -> "sptr"
; hdcSrc : HDC optional -> "sptr"
; x1 : INT -> "sptr"
; y1 : INT -> "sptr"
; rop : ROP_CODE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll"
#cfunc global BitBlt "BitBlt" sptr, int, int, int, int, sptr, int, int, int
; res = BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
; hdc : HDC -> "sptr"
; x : INT -> "int"
; y : INT -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; hdcSrc : HDC optional -> "sptr"
; x1 : INT -> "int"
; y1 : INT -> "int"
; rop : ROP_CODE -> "int"; BOOL BitBlt(HDC hdc, INT x, INT y, INT cx, INT cy, HDC hdcSrc, INT x1, INT y1, ROP_CODE rop)
#uselib "GDI32.dll"
#cfunc global BitBlt "BitBlt" intptr, int, int, int, int, intptr, int, int, int
; res = BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
; hdc : HDC -> "intptr"
; x : INT -> "int"
; y : INT -> "int"
; cx : INT -> "int"
; cy : INT -> "int"
; hdcSrc : HDC optional -> "intptr"
; x1 : INT -> "int"
; y1 : INT -> "int"
; rop : ROP_CODE -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procBitBlt = gdi32.NewProc("BitBlt")
)
// hdc (HDC), x (INT), y (INT), cx (INT), cy (INT), hdcSrc (HDC optional), x1 (INT), y1 (INT), rop (ROP_CODE)
r1, _, err := procBitBlt.Call(
uintptr(hdc),
uintptr(x),
uintptr(y),
uintptr(cx),
uintptr(cy),
uintptr(hdcSrc),
uintptr(x1),
uintptr(y1),
uintptr(rop),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction BitBlt(
hdc: THandle; // HDC
x: Integer; // INT
y: Integer; // INT
cx: Integer; // INT
cy: Integer; // INT
hdcSrc: THandle; // HDC optional
x1: Integer; // INT
y1: Integer; // INT
rop: DWORD // ROP_CODE
): BOOL; stdcall;
external 'GDI32.dll' name 'BitBlt';result := DllCall("GDI32\BitBlt"
, "Ptr", hdc ; HDC
, "Int", x ; INT
, "Int", y ; INT
, "Int", cx ; INT
, "Int", cy ; INT
, "Ptr", hdcSrc ; HDC optional
, "Int", x1 ; INT
, "Int", y1 ; INT
, "UInt", rop ; ROP_CODE
, "Int") ; return: BOOL●BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop) = DLL("GDI32.dll", "bool BitBlt(void*, int, int, int, int, void*, int, int, dword)")
# 呼び出し: BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
# hdc : HDC -> "void*"
# x : INT -> "int"
# y : INT -> "int"
# cx : INT -> "int"
# cy : INT -> "int"
# hdcSrc : HDC optional -> "void*"
# x1 : INT -> "int"
# y1 : INT -> "int"
# rop : ROP_CODE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn BitBlt(
hdc: ?*anyopaque, // HDC
x: i32, // INT
y: i32, // INT
cx: i32, // INT
cy: i32, // INT
hdcSrc: ?*anyopaque, // HDC optional
x1: i32, // INT
y1: i32, // INT
rop: u32 // ROP_CODE
) callconv(std.os.windows.WINAPI) i32;proc BitBlt(
hdc: pointer, # HDC
x: int32, # INT
y: int32, # INT
cx: int32, # INT
cy: int32, # INT
hdcSrc: pointer, # HDC optional
x1: int32, # INT
y1: int32, # INT
rop: uint32 # ROP_CODE
): int32 {.importc: "BitBlt", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int BitBlt(
void* hdc, // HDC
int x, // INT
int y, // INT
int cx, // INT
int cy, // INT
void* hdcSrc, // HDC optional
int x1, // INT
int y1, // INT
uint rop // ROP_CODE
);ccall((:BitBlt, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Int32, Int32, Int32, Ptr{Cvoid}, Int32, Int32, UInt32),
hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
# hdc : HDC -> Ptr{Cvoid}
# x : INT -> Int32
# y : INT -> Int32
# cx : INT -> Int32
# cy : INT -> Int32
# hdcSrc : HDC optional -> Ptr{Cvoid}
# x1 : INT -> Int32
# y1 : INT -> Int32
# rop : ROP_CODE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t BitBlt(
void* hdc,
int32_t x,
int32_t y,
int32_t cx,
int32_t cy,
void* hdcSrc,
int32_t x1,
int32_t y1,
uint32_t rop);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
-- hdc : HDC
-- x : INT
-- y : INT
-- cx : INT
-- cy : INT
-- hdcSrc : HDC optional
-- x1 : INT
-- y1 : INT
-- rop : ROP_CODE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const BitBlt = lib.func('__stdcall', 'BitBlt', 'int32_t', ['void *', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'void *', 'int32_t', 'int32_t', 'uint32_t']);
// BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
// hdc : HDC -> 'void *'
// x : INT -> 'int32_t'
// y : INT -> 'int32_t'
// cx : INT -> 'int32_t'
// cy : INT -> 'int32_t'
// hdcSrc : HDC optional -> 'void *'
// x1 : INT -> 'int32_t'
// y1 : INT -> 'int32_t'
// rop : ROP_CODE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
BitBlt: { parameters: ["pointer", "i32", "i32", "i32", "i32", "pointer", "i32", "i32", "u32"], result: "i32" },
});
// lib.symbols.BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop)
// hdc : HDC -> "pointer"
// x : INT -> "i32"
// y : INT -> "i32"
// cx : INT -> "i32"
// cy : INT -> "i32"
// hdcSrc : HDC optional -> "pointer"
// x1 : INT -> "i32"
// y1 : INT -> "i32"
// rop : ROP_CODE -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t BitBlt(
void* hdc,
int32_t x,
int32_t y,
int32_t cx,
int32_t cy,
void* hdcSrc,
int32_t x1,
int32_t y1,
uint32_t rop);
C, "GDI32.dll");
// $ffi->BitBlt(hdc, x, y, cx, cy, hdcSrc, x1, y1, rop);
// hdc : HDC
// x : INT
// y : INT
// cx : INT
// cy : INT
// hdcSrc : HDC optional
// x1 : INT
// y1 : INT
// rop : ROP_CODE
// 構造体/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);
boolean BitBlt(
Pointer hdc, // HDC
int x, // INT
int y, // INT
int cx, // INT
int cy, // INT
Pointer hdcSrc, // HDC optional
int x1, // INT
int y1, // INT
int rop // ROP_CODE
);
}@[Link("gdi32")]
lib LibGDI32
fun BitBlt = BitBlt(
hdc : Void*, # HDC
x : Int32, # INT
y : Int32, # INT
cx : Int32, # INT
cy : Int32, # INT
hdcSrc : Void*, # HDC optional
x1 : Int32, # INT
y1 : Int32, # INT
rop : UInt32 # ROP_CODE
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef BitBltNative = Int32 Function(Pointer<Void>, Int32, Int32, Int32, Int32, Pointer<Void>, Int32, Int32, Uint32);
typedef BitBltDart = int Function(Pointer<Void>, int, int, int, int, Pointer<Void>, int, int, int);
final BitBlt = DynamicLibrary.open('GDI32.dll')
.lookupFunction<BitBltNative, BitBltDart>('BitBlt');
// hdc : HDC -> Pointer<Void>
// x : INT -> Int32
// y : INT -> Int32
// cx : INT -> Int32
// cy : INT -> Int32
// hdcSrc : HDC optional -> Pointer<Void>
// x1 : INT -> Int32
// y1 : INT -> Int32
// rop : ROP_CODE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function BitBlt(
hdc: THandle; // HDC
x: Integer; // INT
y: Integer; // INT
cx: Integer; // INT
cy: Integer; // INT
hdcSrc: THandle; // HDC optional
x1: Integer; // INT
y1: Integer; // INT
rop: DWORD // ROP_CODE
): BOOL; stdcall;
external 'GDI32.dll' name 'BitBlt';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "BitBlt"
c_BitBlt :: Ptr () -> Int32 -> Int32 -> Int32 -> Int32 -> Ptr () -> Int32 -> Int32 -> Word32 -> IO CInt
-- hdc : HDC -> Ptr ()
-- x : INT -> Int32
-- y : INT -> Int32
-- cx : INT -> Int32
-- cy : INT -> Int32
-- hdcSrc : HDC optional -> Ptr ()
-- x1 : INT -> Int32
-- y1 : INT -> Int32
-- rop : ROP_CODE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let bitblt =
foreign "BitBlt"
((ptr void) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> (ptr void) @-> int32_t @-> int32_t @-> uint32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* x : INT -> int32_t *)
(* y : INT -> int32_t *)
(* cx : INT -> int32_t *)
(* cy : INT -> int32_t *)
(* hdcSrc : HDC optional -> (ptr void) *)
(* x1 : INT -> int32_t *)
(* y1 : INT -> int32_t *)
(* rop : ROP_CODE -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdi32 (t "GDI32.dll"))
(cffi:use-foreign-library gdi32)
(cffi:defcfun ("BitBlt" bit-blt :convention :stdcall) :int32
(hdc :pointer) ; HDC
(x :int32) ; INT
(y :int32) ; INT
(cx :int32) ; INT
(cy :int32) ; INT
(hdc-src :pointer) ; HDC optional
(x1 :int32) ; INT
(y1 :int32) ; INT
(rop :uint32)) ; ROP_CODE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $BitBlt = Win32::API::More->new('GDI32',
'BOOL BitBlt(HANDLE hdc, int x, int y, int cx, int cy, HANDLE hdcSrc, int x1, int y1, DWORD rop)');
# my $ret = $BitBlt->Call($hdc, $x, $y, $cx, $cy, $hdcSrc, $x1, $y1, $rop);
# hdc : HDC -> HANDLE
# x : INT -> int
# y : INT -> int
# cx : INT -> int
# cy : INT -> int
# hdcSrc : HDC optional -> HANDLE
# x1 : INT -> int
# y1 : INT -> int
# rop : ROP_CODE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f GetDIBits — ビットマップのビットをDIB形式で取得する。
- f GetDeviceCaps — デバイスの能力や属性情報を取得する。
- f MaskBlt — マスクを用いてビットマップを合成転送する。
- f PlgBlt — 平行四辺形領域へビットマップを転送する。
- f SetDIBits — DIBのビットでビットマップのピクセルを設定する。
- f StretchBlt — ソース矩形を伸縮しながら転送先矩形へビット転送する。
- f StretchDIBits — DIBのピクセルを伸縮して転送先矩形へ転送する。