StretchDIBits
関数シグネチャ
// GDI32.dll
#include <windows.h>
INT StretchDIBits(
HDC hdc,
INT xDest,
INT yDest,
INT DestWidth,
INT DestHeight,
INT xSrc,
INT ySrc,
INT SrcWidth,
INT SrcHeight,
const void* lpBits, // optional
const BITMAPINFO* lpbmi,
DIB_USAGE iUsage,
ROP_CODE rop
);パラメーター
| 名前 | 型 | 方向 | 説明 | ||||||
|---|---|---|---|---|---|---|---|---|---|
| hdc | HDC | in | 変換先デバイスコンテキストのハンドル。 | ||||||
| xDest | INT | in | 変換先矩形の左上隅の x 座標(論理単位)。 | ||||||
| yDest | INT | in | 変換先矩形の左上隅の y 座標(論理単位)。 | ||||||
| DestWidth | INT | in | 変換先矩形の幅(論理単位)。 | ||||||
| DestHeight | INT | in | 変換先矩形の高さ(論理単位)。 | ||||||
| xSrc | INT | in | イメージ内の変換元矩形の x 座標(ピクセル単位)。 | ||||||
| ySrc | INT | in | イメージ内の変換元矩形の y 座標(ピクセル単位)。 | ||||||
| SrcWidth | INT | in | イメージ内の変換元矩形の幅(ピクセル単位)。 | ||||||
| SrcHeight | INT | in | イメージ内の変換元矩形の高さ(ピクセル単位)。 | ||||||
| lpBits | void* | inoptional | バイト配列として格納されたイメージビットへのポインター。詳細については、「解説」セクションを参照してください。 | ||||||
| lpbmi | BITMAPINFO* | in | DIB に関する情報を格納する BITMAPINFO 構造体へのポインター。 | ||||||
| iUsage | DIB_USAGE | in | BITMAPINFO 構造体の bmiColors メンバーが指定されているかどうか、指定されている場合は bmiColors が明示的な赤、緑、青 (RGB) の値を格納しているか、それともインデックスを格納しているかを指定します。iUsage パラメーターは、次の値のいずれかでなければなりません。
詳細については、「解説」セクションを参照してください。 | ||||||
| rop | ROP_CODE | in | 変換元ピクセル、変換先デバイスコンテキストの現在のブラシ、および変換先ピクセルをどのように組み合わせて新しいイメージを形成するかを指定するラスター演算コード。一般的なラスター演算コードの一覧については、BitBlt を参照してください。 |
戻り値の型: INT
公式ドキュメント
StretchDIBits 関数は、DIB、JPEG、または PNG イメージ内のピクセル矩形のカラーデータを、指定された変換先矩形にコピーします。
戻り値
関数が成功した場合、戻り値はコピーされたスキャンラインの数です。なお、ミラー化されたコンテンツの場合、この値は負になることがあります。
関数が失敗した場合、またはスキャンラインが 1 つもコピーされなかった場合、戻り値は 0 です。
ドライバーが StretchDIBits に渡された JPEG または PNG ファイルイメージをサポートできない場合、関数は失敗し GDI_ERROR を返します。失敗が発生した場合、アプリケーションは独自の JPEG または PNG サポートにフォールバックしてイメージをビットマップへ展開し、そのビットマップを StretchDIBits に渡す必要があります。
解説(Remarks)
ボトムアップ DIB の原点は左下隅であり、トップダウン DIB の原点は左上隅です。
StretchDIBits は、nSrcWidth と nDestWidth パラメーターの符号が異なる場合、または nSrcHeight と nDestHeight パラメーターの符号が異なる場合に、ビットマップのミラーイメージを作成します。nSrcWidth と nDestWidth の符号が異なる場合、関数は x 軸に沿ったビットマップのミラーイメージを作成します。nSrcHeight と nDestHeight の符号が異なる場合、関数は y 軸に沿ったビットマップのミラーイメージを作成します。
StretchDIBits は、DIB の BITMAPINFOHEADER 構造体の biHeight メンバーの符号が負の場合、トップダウンイメージを作成します。コード例については、Sizing a JPEG or PNG Image を参照してください。
この関数では、変換元イメージとして JPEG または PNG イメージを渡すことができます。各パラメーターの使用方法は同じですが、次の点が異なります。
- BITMAPINFOHEADER の biCompression メンバーが BI_JPEG または BI_PNG の場合、lpBits はそれぞれ JPEG または PNG イメージを格納するバッファーを指します。BITMAPINFOHEADER 構造体の biSizeImage メンバーは、バッファーのサイズを指定します。iUsage パラメーターは DIB_RGB_COLORS に設定する必要があります。dwRop パラメーターは SRCCOPY に設定する必要があります。
- 印刷時にメタファイルが適切にスプールされるようにするには、StretchDIBits を呼び出す前に、プリンターが JPEG または PNG イメージをそれぞれ認識することを確認するために、アプリケーションは CHECKJPEGFORMAT または CHECKPNGFORMAT エスケープを呼び出す必要があります。
Examples
例については、Sizing a JPEG or PNG Image を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// GDI32.dll
#include <windows.h>
INT StretchDIBits(
HDC hdc,
INT xDest,
INT yDest,
INT DestWidth,
INT DestHeight,
INT xSrc,
INT ySrc,
INT SrcWidth,
INT SrcHeight,
const void* lpBits, // optional
const BITMAPINFO* lpbmi,
DIB_USAGE iUsage,
ROP_CODE rop
);[DllImport("GDI32.dll", ExactSpelling = true)]
static extern int StretchDIBits(
IntPtr hdc, // HDC
int xDest, // INT
int yDest, // INT
int DestWidth, // INT
int DestHeight, // INT
int xSrc, // INT
int ySrc, // INT
int SrcWidth, // INT
int SrcHeight, // INT
IntPtr lpBits, // void* optional
IntPtr lpbmi, // BITMAPINFO*
uint iUsage, // DIB_USAGE
uint rop // ROP_CODE
);<DllImport("GDI32.dll", ExactSpelling:=True)>
Public Shared Function StretchDIBits(
hdc As IntPtr, ' HDC
xDest As Integer, ' INT
yDest As Integer, ' INT
DestWidth As Integer, ' INT
DestHeight As Integer, ' INT
xSrc As Integer, ' INT
ySrc As Integer, ' INT
SrcWidth As Integer, ' INT
SrcHeight As Integer, ' INT
lpBits As IntPtr, ' void* optional
lpbmi As IntPtr, ' BITMAPINFO*
iUsage As UInteger, ' DIB_USAGE
rop As UInteger ' ROP_CODE
) As Integer
End Function' hdc : HDC
' xDest : INT
' yDest : INT
' DestWidth : INT
' DestHeight : INT
' xSrc : INT
' ySrc : INT
' SrcWidth : INT
' SrcHeight : INT
' lpBits : void* optional
' lpbmi : BITMAPINFO*
' iUsage : DIB_USAGE
' rop : ROP_CODE
Declare PtrSafe Function StretchDIBits Lib "gdi32" ( _
ByVal hdc As LongPtr, _
ByVal xDest As Long, _
ByVal yDest As Long, _
ByVal DestWidth As Long, _
ByVal DestHeight As Long, _
ByVal xSrc As Long, _
ByVal ySrc As Long, _
ByVal SrcWidth As Long, _
ByVal SrcHeight As Long, _
ByVal lpBits As LongPtr, _
ByVal lpbmi As LongPtr, _
ByVal iUsage 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
StretchDIBits = ctypes.windll.gdi32.StretchDIBits
StretchDIBits.restype = ctypes.c_int
StretchDIBits.argtypes = [
wintypes.HANDLE, # hdc : HDC
ctypes.c_int, # xDest : INT
ctypes.c_int, # yDest : INT
ctypes.c_int, # DestWidth : INT
ctypes.c_int, # DestHeight : INT
ctypes.c_int, # xSrc : INT
ctypes.c_int, # ySrc : INT
ctypes.c_int, # SrcWidth : INT
ctypes.c_int, # SrcHeight : INT
ctypes.POINTER(None), # lpBits : void* optional
ctypes.c_void_p, # lpbmi : BITMAPINFO*
wintypes.DWORD, # iUsage : DIB_USAGE
wintypes.DWORD, # rop : ROP_CODE
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('GDI32.dll')
StretchDIBits = Fiddle::Function.new(
lib['StretchDIBits'],
[
Fiddle::TYPE_VOIDP, # hdc : HDC
Fiddle::TYPE_INT, # xDest : INT
Fiddle::TYPE_INT, # yDest : INT
Fiddle::TYPE_INT, # DestWidth : INT
Fiddle::TYPE_INT, # DestHeight : INT
Fiddle::TYPE_INT, # xSrc : INT
Fiddle::TYPE_INT, # ySrc : INT
Fiddle::TYPE_INT, # SrcWidth : INT
Fiddle::TYPE_INT, # SrcHeight : INT
Fiddle::TYPE_VOIDP, # lpBits : void* optional
Fiddle::TYPE_VOIDP, # lpbmi : BITMAPINFO*
-Fiddle::TYPE_INT, # iUsage : DIB_USAGE
-Fiddle::TYPE_INT, # rop : ROP_CODE
],
Fiddle::TYPE_INT)#[link(name = "gdi32")]
extern "system" {
fn StretchDIBits(
hdc: *mut core::ffi::c_void, // HDC
xDest: i32, // INT
yDest: i32, // INT
DestWidth: i32, // INT
DestHeight: i32, // INT
xSrc: i32, // INT
ySrc: i32, // INT
SrcWidth: i32, // INT
SrcHeight: i32, // INT
lpBits: *const (), // void* optional
lpbmi: *const BITMAPINFO, // BITMAPINFO*
iUsage: u32, // DIB_USAGE
rop: u32 // ROP_CODE
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("GDI32.dll")]
public static extern int StretchDIBits(IntPtr hdc, int xDest, int yDest, int DestWidth, int DestHeight, int xSrc, int ySrc, int SrcWidth, int SrcHeight, IntPtr lpBits, IntPtr lpbmi, uint iUsage, uint rop);
"@
$api = Add-Type -MemberDefinition $sig -Name 'GDI32_StretchDIBits' -Namespace Win32 -PassThru
# $api::StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop)#uselib "GDI32.dll"
#func global StretchDIBits "StretchDIBits" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; StretchDIBits hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, varptr(lpbmi), iUsage, rop ; 戻り値は stat
; hdc : HDC -> "sptr"
; xDest : INT -> "sptr"
; yDest : INT -> "sptr"
; DestWidth : INT -> "sptr"
; DestHeight : INT -> "sptr"
; xSrc : INT -> "sptr"
; ySrc : INT -> "sptr"
; SrcWidth : INT -> "sptr"
; SrcHeight : INT -> "sptr"
; lpBits : void* optional -> "sptr"
; lpbmi : BITMAPINFO* -> "sptr"
; iUsage : DIB_USAGE -> "sptr"
; rop : ROP_CODE -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "GDI32.dll" #cfunc global StretchDIBits "StretchDIBits" sptr, int, int, int, int, int, int, int, int, sptr, var, int, int ; res = StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop) ; hdc : HDC -> "sptr" ; xDest : INT -> "int" ; yDest : INT -> "int" ; DestWidth : INT -> "int" ; DestHeight : INT -> "int" ; xSrc : INT -> "int" ; ySrc : INT -> "int" ; SrcWidth : INT -> "int" ; SrcHeight : INT -> "int" ; lpBits : void* optional -> "sptr" ; lpbmi : BITMAPINFO* -> "var" ; iUsage : DIB_USAGE -> "int" ; rop : ROP_CODE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "GDI32.dll" #cfunc global StretchDIBits "StretchDIBits" sptr, int, int, int, int, int, int, int, int, sptr, sptr, int, int ; res = StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, varptr(lpbmi), iUsage, rop) ; hdc : HDC -> "sptr" ; xDest : INT -> "int" ; yDest : INT -> "int" ; DestWidth : INT -> "int" ; DestHeight : INT -> "int" ; xSrc : INT -> "int" ; ySrc : INT -> "int" ; SrcWidth : INT -> "int" ; SrcHeight : INT -> "int" ; lpBits : void* optional -> "sptr" ; lpbmi : BITMAPINFO* -> "sptr" ; iUsage : DIB_USAGE -> "int" ; rop : ROP_CODE -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; INT StretchDIBits(HDC hdc, INT xDest, INT yDest, INT DestWidth, INT DestHeight, INT xSrc, INT ySrc, INT SrcWidth, INT SrcHeight, void* lpBits, BITMAPINFO* lpbmi, DIB_USAGE iUsage, ROP_CODE rop) #uselib "GDI32.dll" #cfunc global StretchDIBits "StretchDIBits" intptr, int, int, int, int, int, int, int, int, intptr, var, int, int ; res = StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop) ; hdc : HDC -> "intptr" ; xDest : INT -> "int" ; yDest : INT -> "int" ; DestWidth : INT -> "int" ; DestHeight : INT -> "int" ; xSrc : INT -> "int" ; ySrc : INT -> "int" ; SrcWidth : INT -> "int" ; SrcHeight : INT -> "int" ; lpBits : void* optional -> "intptr" ; lpbmi : BITMAPINFO* -> "var" ; iUsage : DIB_USAGE -> "int" ; rop : ROP_CODE -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; INT StretchDIBits(HDC hdc, INT xDest, INT yDest, INT DestWidth, INT DestHeight, INT xSrc, INT ySrc, INT SrcWidth, INT SrcHeight, void* lpBits, BITMAPINFO* lpbmi, DIB_USAGE iUsage, ROP_CODE rop) #uselib "GDI32.dll" #cfunc global StretchDIBits "StretchDIBits" intptr, int, int, int, int, int, int, int, int, intptr, intptr, int, int ; res = StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, varptr(lpbmi), iUsage, rop) ; hdc : HDC -> "intptr" ; xDest : INT -> "int" ; yDest : INT -> "int" ; DestWidth : INT -> "int" ; DestHeight : INT -> "int" ; xSrc : INT -> "int" ; ySrc : INT -> "int" ; SrcWidth : INT -> "int" ; SrcHeight : INT -> "int" ; lpBits : void* optional -> "intptr" ; lpbmi : BITMAPINFO* -> "intptr" ; iUsage : DIB_USAGE -> "int" ; rop : ROP_CODE -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdi32 = windows.NewLazySystemDLL("GDI32.dll")
procStretchDIBits = gdi32.NewProc("StretchDIBits")
)
// hdc (HDC), xDest (INT), yDest (INT), DestWidth (INT), DestHeight (INT), xSrc (INT), ySrc (INT), SrcWidth (INT), SrcHeight (INT), lpBits (void* optional), lpbmi (BITMAPINFO*), iUsage (DIB_USAGE), rop (ROP_CODE)
r1, _, err := procStretchDIBits.Call(
uintptr(hdc),
uintptr(xDest),
uintptr(yDest),
uintptr(DestWidth),
uintptr(DestHeight),
uintptr(xSrc),
uintptr(ySrc),
uintptr(SrcWidth),
uintptr(SrcHeight),
uintptr(lpBits),
uintptr(lpbmi),
uintptr(iUsage),
uintptr(rop),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // INTfunction StretchDIBits(
hdc: THandle; // HDC
xDest: Integer; // INT
yDest: Integer; // INT
DestWidth: Integer; // INT
DestHeight: Integer; // INT
xSrc: Integer; // INT
ySrc: Integer; // INT
SrcWidth: Integer; // INT
SrcHeight: Integer; // INT
lpBits: Pointer; // void* optional
lpbmi: Pointer; // BITMAPINFO*
iUsage: DWORD; // DIB_USAGE
rop: DWORD // ROP_CODE
): Integer; stdcall;
external 'GDI32.dll' name 'StretchDIBits';result := DllCall("GDI32\StretchDIBits"
, "Ptr", hdc ; HDC
, "Int", xDest ; INT
, "Int", yDest ; INT
, "Int", DestWidth ; INT
, "Int", DestHeight ; INT
, "Int", xSrc ; INT
, "Int", ySrc ; INT
, "Int", SrcWidth ; INT
, "Int", SrcHeight ; INT
, "Ptr", lpBits ; void* optional
, "Ptr", lpbmi ; BITMAPINFO*
, "UInt", iUsage ; DIB_USAGE
, "UInt", rop ; ROP_CODE
, "Int") ; return: INT●StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop) = DLL("GDI32.dll", "int StretchDIBits(void*, int, int, int, int, int, int, int, int, void*, void*, dword, dword)")
# 呼び出し: StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop)
# hdc : HDC -> "void*"
# xDest : INT -> "int"
# yDest : INT -> "int"
# DestWidth : INT -> "int"
# DestHeight : INT -> "int"
# xSrc : INT -> "int"
# ySrc : INT -> "int"
# SrcWidth : INT -> "int"
# SrcHeight : INT -> "int"
# lpBits : void* optional -> "void*"
# lpbmi : BITMAPINFO* -> "void*"
# iUsage : DIB_USAGE -> "dword"
# rop : ROP_CODE -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdi32" fn StretchDIBits(
hdc: ?*anyopaque, // HDC
xDest: i32, // INT
yDest: i32, // INT
DestWidth: i32, // INT
DestHeight: i32, // INT
xSrc: i32, // INT
ySrc: i32, // INT
SrcWidth: i32, // INT
SrcHeight: i32, // INT
lpBits: ?*anyopaque, // void* optional
lpbmi: [*c]BITMAPINFO, // BITMAPINFO*
iUsage: u32, // DIB_USAGE
rop: u32 // ROP_CODE
) callconv(std.os.windows.WINAPI) i32;proc StretchDIBits(
hdc: pointer, # HDC
xDest: int32, # INT
yDest: int32, # INT
DestWidth: int32, # INT
DestHeight: int32, # INT
xSrc: int32, # INT
ySrc: int32, # INT
SrcWidth: int32, # INT
SrcHeight: int32, # INT
lpBits: pointer, # void* optional
lpbmi: ptr BITMAPINFO, # BITMAPINFO*
iUsage: uint32, # DIB_USAGE
rop: uint32 # ROP_CODE
): int32 {.importc: "StretchDIBits", stdcall, dynlib: "GDI32.dll".}pragma(lib, "gdi32");
extern(Windows)
int StretchDIBits(
void* hdc, // HDC
int xDest, // INT
int yDest, // INT
int DestWidth, // INT
int DestHeight, // INT
int xSrc, // INT
int ySrc, // INT
int SrcWidth, // INT
int SrcHeight, // INT
void* lpBits, // void* optional
BITMAPINFO* lpbmi, // BITMAPINFO*
uint iUsage, // DIB_USAGE
uint rop // ROP_CODE
);ccall((:StretchDIBits, "GDI32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Ptr{Cvoid}, Ptr{BITMAPINFO}, UInt32, UInt32),
hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop)
# hdc : HDC -> Ptr{Cvoid}
# xDest : INT -> Int32
# yDest : INT -> Int32
# DestWidth : INT -> Int32
# DestHeight : INT -> Int32
# xSrc : INT -> Int32
# ySrc : INT -> Int32
# SrcWidth : INT -> Int32
# SrcHeight : INT -> Int32
# lpBits : void* optional -> Ptr{Cvoid}
# lpbmi : BITMAPINFO* -> Ptr{BITMAPINFO}
# iUsage : DIB_USAGE -> UInt32
# rop : ROP_CODE -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t StretchDIBits(
void* hdc,
int32_t xDest,
int32_t yDest,
int32_t DestWidth,
int32_t DestHeight,
int32_t xSrc,
int32_t ySrc,
int32_t SrcWidth,
int32_t SrcHeight,
void* lpBits,
void* lpbmi,
uint32_t iUsage,
uint32_t rop);
]]
local gdi32 = ffi.load("gdi32")
-- gdi32.StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop)
-- hdc : HDC
-- xDest : INT
-- yDest : INT
-- DestWidth : INT
-- DestHeight : INT
-- xSrc : INT
-- ySrc : INT
-- SrcWidth : INT
-- SrcHeight : INT
-- lpBits : void* optional
-- lpbmi : BITMAPINFO*
-- iUsage : DIB_USAGE
-- rop : ROP_CODE
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('GDI32.dll');
const StretchDIBits = lib.func('__stdcall', 'StretchDIBits', 'int32_t', ['void *', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'int32_t', 'void *', 'void *', 'uint32_t', 'uint32_t']);
// StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop)
// hdc : HDC -> 'void *'
// xDest : INT -> 'int32_t'
// yDest : INT -> 'int32_t'
// DestWidth : INT -> 'int32_t'
// DestHeight : INT -> 'int32_t'
// xSrc : INT -> 'int32_t'
// ySrc : INT -> 'int32_t'
// SrcWidth : INT -> 'int32_t'
// SrcHeight : INT -> 'int32_t'
// lpBits : void* optional -> 'void *'
// lpbmi : BITMAPINFO* -> 'void *'
// iUsage : DIB_USAGE -> 'uint32_t'
// rop : ROP_CODE -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("GDI32.dll", {
StretchDIBits: { parameters: ["pointer", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "i32", "pointer", "pointer", "u32", "u32"], result: "i32" },
});
// lib.symbols.StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop)
// hdc : HDC -> "pointer"
// xDest : INT -> "i32"
// yDest : INT -> "i32"
// DestWidth : INT -> "i32"
// DestHeight : INT -> "i32"
// xSrc : INT -> "i32"
// ySrc : INT -> "i32"
// SrcWidth : INT -> "i32"
// SrcHeight : INT -> "i32"
// lpBits : void* optional -> "pointer"
// lpbmi : BITMAPINFO* -> "pointer"
// iUsage : DIB_USAGE -> "u32"
// rop : ROP_CODE -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t StretchDIBits(
void* hdc,
int32_t xDest,
int32_t yDest,
int32_t DestWidth,
int32_t DestHeight,
int32_t xSrc,
int32_t ySrc,
int32_t SrcWidth,
int32_t SrcHeight,
void* lpBits,
void* lpbmi,
uint32_t iUsage,
uint32_t rop);
C, "GDI32.dll");
// $ffi->StretchDIBits(hdc, xDest, yDest, DestWidth, DestHeight, xSrc, ySrc, SrcWidth, SrcHeight, lpBits, lpbmi, iUsage, rop);
// hdc : HDC
// xDest : INT
// yDest : INT
// DestWidth : INT
// DestHeight : INT
// xSrc : INT
// ySrc : INT
// SrcWidth : INT
// SrcHeight : INT
// lpBits : void* optional
// lpbmi : BITMAPINFO*
// iUsage : DIB_USAGE
// 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);
int StretchDIBits(
Pointer hdc, // HDC
int xDest, // INT
int yDest, // INT
int DestWidth, // INT
int DestHeight, // INT
int xSrc, // INT
int ySrc, // INT
int SrcWidth, // INT
int SrcHeight, // INT
Pointer lpBits, // void* optional
Pointer lpbmi, // BITMAPINFO*
int iUsage, // DIB_USAGE
int rop // ROP_CODE
);
}@[Link("gdi32")]
lib LibGDI32
fun StretchDIBits = StretchDIBits(
hdc : Void*, # HDC
xDest : Int32, # INT
yDest : Int32, # INT
DestWidth : Int32, # INT
DestHeight : Int32, # INT
xSrc : Int32, # INT
ySrc : Int32, # INT
SrcWidth : Int32, # INT
SrcHeight : Int32, # INT
lpBits : Void*, # void* optional
lpbmi : BITMAPINFO*, # BITMAPINFO*
iUsage : UInt32, # DIB_USAGE
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 StretchDIBitsNative = Int32 Function(Pointer<Void>, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Pointer<Void>, Pointer<Void>, Uint32, Uint32);
typedef StretchDIBitsDart = int Function(Pointer<Void>, int, int, int, int, int, int, int, int, Pointer<Void>, Pointer<Void>, int, int);
final StretchDIBits = DynamicLibrary.open('GDI32.dll')
.lookupFunction<StretchDIBitsNative, StretchDIBitsDart>('StretchDIBits');
// hdc : HDC -> Pointer<Void>
// xDest : INT -> Int32
// yDest : INT -> Int32
// DestWidth : INT -> Int32
// DestHeight : INT -> Int32
// xSrc : INT -> Int32
// ySrc : INT -> Int32
// SrcWidth : INT -> Int32
// SrcHeight : INT -> Int32
// lpBits : void* optional -> Pointer<Void>
// lpbmi : BITMAPINFO* -> Pointer<Void>
// iUsage : DIB_USAGE -> Uint32
// rop : ROP_CODE -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function StretchDIBits(
hdc: THandle; // HDC
xDest: Integer; // INT
yDest: Integer; // INT
DestWidth: Integer; // INT
DestHeight: Integer; // INT
xSrc: Integer; // INT
ySrc: Integer; // INT
SrcWidth: Integer; // INT
SrcHeight: Integer; // INT
lpBits: Pointer; // void* optional
lpbmi: Pointer; // BITMAPINFO*
iUsage: DWORD; // DIB_USAGE
rop: DWORD // ROP_CODE
): Integer; stdcall;
external 'GDI32.dll' name 'StretchDIBits';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "StretchDIBits"
c_StretchDIBits :: Ptr () -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Int32 -> Ptr () -> Ptr () -> Word32 -> Word32 -> IO Int32
-- hdc : HDC -> Ptr ()
-- xDest : INT -> Int32
-- yDest : INT -> Int32
-- DestWidth : INT -> Int32
-- DestHeight : INT -> Int32
-- xSrc : INT -> Int32
-- ySrc : INT -> Int32
-- SrcWidth : INT -> Int32
-- SrcHeight : INT -> Int32
-- lpBits : void* optional -> Ptr ()
-- lpbmi : BITMAPINFO* -> Ptr ()
-- iUsage : DIB_USAGE -> Word32
-- rop : ROP_CODE -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let stretchdibits =
foreign "StretchDIBits"
((ptr void) @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> int32_t @-> (ptr void) @-> (ptr void) @-> uint32_t @-> uint32_t @-> returning int32_t)
(* hdc : HDC -> (ptr void) *)
(* xDest : INT -> int32_t *)
(* yDest : INT -> int32_t *)
(* DestWidth : INT -> int32_t *)
(* DestHeight : INT -> int32_t *)
(* xSrc : INT -> int32_t *)
(* ySrc : INT -> int32_t *)
(* SrcWidth : INT -> int32_t *)
(* SrcHeight : INT -> int32_t *)
(* lpBits : void* optional -> (ptr void) *)
(* lpbmi : BITMAPINFO* -> (ptr void) *)
(* iUsage : DIB_USAGE -> uint32_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 ("StretchDIBits" stretch-dibits :convention :stdcall) :int32
(hdc :pointer) ; HDC
(x-dest :int32) ; INT
(y-dest :int32) ; INT
(dest-width :int32) ; INT
(dest-height :int32) ; INT
(x-src :int32) ; INT
(y-src :int32) ; INT
(src-width :int32) ; INT
(src-height :int32) ; INT
(lp-bits :pointer) ; void* optional
(lpbmi :pointer) ; BITMAPINFO*
(i-usage :uint32) ; DIB_USAGE
(rop :uint32)) ; ROP_CODE
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $StretchDIBits = Win32::API::More->new('GDI32',
'int StretchDIBits(HANDLE hdc, int xDest, int yDest, int DestWidth, int DestHeight, int xSrc, int ySrc, int SrcWidth, int SrcHeight, LPVOID lpBits, LPVOID lpbmi, DWORD iUsage, DWORD rop)');
# my $ret = $StretchDIBits->Call($hdc, $xDest, $yDest, $DestWidth, $DestHeight, $xSrc, $ySrc, $SrcWidth, $SrcHeight, $lpBits, $lpbmi, $iUsage, $rop);
# hdc : HDC -> HANDLE
# xDest : INT -> int
# yDest : INT -> int
# DestWidth : INT -> int
# DestHeight : INT -> int
# xSrc : INT -> int
# ySrc : INT -> int
# SrcWidth : INT -> int
# SrcHeight : INT -> int
# lpBits : void* optional -> LPVOID
# lpbmi : BITMAPINFO* -> LPVOID
# iUsage : DIB_USAGE -> DWORD
# rop : ROP_CODE -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f SetMapMode — デバイスコンテキストの座標写像モードを設定する。
- f SetStretchBltMode — ビットマップ伸縮時のラスタ補間モードを設定する。