ホーム › Graphics.GdiPlus › GdipCreateHBITMAPFromBitmap
GdipCreateHBITMAPFromBitmap
関数ビットマップからGDIのHBITMAPハンドルを作成する。
シグネチャ
// gdiplus.dll
#include <windows.h>
Status GdipCreateHBITMAPFromBitmap(
GpBitmap* bitmap,
HBITMAP* hbmReturn,
DWORD background
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| bitmap | GpBitmap* | inout | 変換元のGpBitmapオブジェクトへのポインタ。 |
| hbmReturn | HBITMAP* | inout | 生成されたGDIビットマップハンドル(HBITMAP)を受け取る出力先ポインタ。 |
| background | DWORD | in | 透明部分に合成する背景色をARGB形式で指定する。 |
戻り値の型: Status
各言語での呼び出し定義
// gdiplus.dll
#include <windows.h>
Status GdipCreateHBITMAPFromBitmap(
GpBitmap* bitmap,
HBITMAP* hbmReturn,
DWORD background
);[DllImport("gdiplus.dll", ExactSpelling = true)]
static extern int GdipCreateHBITMAPFromBitmap(
IntPtr bitmap, // GpBitmap* in/out
IntPtr hbmReturn, // HBITMAP* in/out
uint background // DWORD
);<DllImport("gdiplus.dll", ExactSpelling:=True)>
Public Shared Function GdipCreateHBITMAPFromBitmap(
bitmap As IntPtr, ' GpBitmap* in/out
hbmReturn As IntPtr, ' HBITMAP* in/out
background As UInteger ' DWORD
) As Integer
End Function' bitmap : GpBitmap* in/out
' hbmReturn : HBITMAP* in/out
' background : DWORD
Declare PtrSafe Function GdipCreateHBITMAPFromBitmap Lib "gdiplus" ( _
ByVal bitmap As LongPtr, _
ByVal hbmReturn As LongPtr, _
ByVal background As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
GdipCreateHBITMAPFromBitmap = ctypes.windll.gdiplus.GdipCreateHBITMAPFromBitmap
GdipCreateHBITMAPFromBitmap.restype = ctypes.c_int
GdipCreateHBITMAPFromBitmap.argtypes = [
ctypes.c_void_p, # bitmap : GpBitmap* in/out
ctypes.c_void_p, # hbmReturn : HBITMAP* in/out
wintypes.DWORD, # background : DWORD
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('gdiplus.dll')
GdipCreateHBITMAPFromBitmap = Fiddle::Function.new(
lib['GdipCreateHBITMAPFromBitmap'],
[
Fiddle::TYPE_VOIDP, # bitmap : GpBitmap* in/out
Fiddle::TYPE_VOIDP, # hbmReturn : HBITMAP* in/out
-Fiddle::TYPE_INT, # background : DWORD
],
Fiddle::TYPE_INT)#[link(name = "gdiplus")]
extern "system" {
fn GdipCreateHBITMAPFromBitmap(
bitmap: *mut GpBitmap, // GpBitmap* in/out
hbmReturn: *mut *mut core::ffi::c_void, // HBITMAP* in/out
background: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("gdiplus.dll")]
public static extern int GdipCreateHBITMAPFromBitmap(IntPtr bitmap, IntPtr hbmReturn, uint background);
"@
$api = Add-Type -MemberDefinition $sig -Name 'gdiplus_GdipCreateHBITMAPFromBitmap' -Namespace Win32 -PassThru
# $api::GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background)#uselib "gdiplus.dll"
#func global GdipCreateHBITMAPFromBitmap "GdipCreateHBITMAPFromBitmap" sptr, sptr, sptr
; GdipCreateHBITMAPFromBitmap varptr(bitmap), hbmReturn, background ; 戻り値は stat
; bitmap : GpBitmap* in/out -> "sptr"
; hbmReturn : HBITMAP* in/out -> "sptr"
; background : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "gdiplus.dll" #cfunc global GdipCreateHBITMAPFromBitmap "GdipCreateHBITMAPFromBitmap" var, sptr, int ; res = GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background) ; bitmap : GpBitmap* in/out -> "var" ; hbmReturn : HBITMAP* in/out -> "sptr" ; background : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "gdiplus.dll" #cfunc global GdipCreateHBITMAPFromBitmap "GdipCreateHBITMAPFromBitmap" sptr, sptr, int ; res = GdipCreateHBITMAPFromBitmap(varptr(bitmap), hbmReturn, background) ; bitmap : GpBitmap* in/out -> "sptr" ; hbmReturn : HBITMAP* in/out -> "sptr" ; background : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; Status GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, HBITMAP* hbmReturn, DWORD background) #uselib "gdiplus.dll" #cfunc global GdipCreateHBITMAPFromBitmap "GdipCreateHBITMAPFromBitmap" var, intptr, int ; res = GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background) ; bitmap : GpBitmap* in/out -> "var" ; hbmReturn : HBITMAP* in/out -> "intptr" ; background : DWORD -> "int" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; Status GdipCreateHBITMAPFromBitmap(GpBitmap* bitmap, HBITMAP* hbmReturn, DWORD background) #uselib "gdiplus.dll" #cfunc global GdipCreateHBITMAPFromBitmap "GdipCreateHBITMAPFromBitmap" intptr, intptr, int ; res = GdipCreateHBITMAPFromBitmap(varptr(bitmap), hbmReturn, background) ; bitmap : GpBitmap* in/out -> "intptr" ; hbmReturn : HBITMAP* in/out -> "intptr" ; background : DWORD -> "int" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
gdiplus = windows.NewLazySystemDLL("gdiplus.dll")
procGdipCreateHBITMAPFromBitmap = gdiplus.NewProc("GdipCreateHBITMAPFromBitmap")
)
// bitmap (GpBitmap* in/out), hbmReturn (HBITMAP* in/out), background (DWORD)
r1, _, err := procGdipCreateHBITMAPFromBitmap.Call(
uintptr(bitmap),
uintptr(hbmReturn),
uintptr(background),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // Statusfunction GdipCreateHBITMAPFromBitmap(
bitmap: Pointer; // GpBitmap* in/out
hbmReturn: Pointer; // HBITMAP* in/out
background: DWORD // DWORD
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipCreateHBITMAPFromBitmap';result := DllCall("gdiplus\GdipCreateHBITMAPFromBitmap"
, "Ptr", bitmap ; GpBitmap* in/out
, "Ptr", hbmReturn ; HBITMAP* in/out
, "UInt", background ; DWORD
, "Int") ; return: Status●GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background) = DLL("gdiplus.dll", "int GdipCreateHBITMAPFromBitmap(void*, void*, dword)")
# 呼び出し: GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background)
# bitmap : GpBitmap* in/out -> "void*"
# hbmReturn : HBITMAP* in/out -> "void*"
# background : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "gdiplus" fn GdipCreateHBITMAPFromBitmap(
bitmap: [*c]GpBitmap, // GpBitmap* in/out
hbmReturn: ?*anyopaque, // HBITMAP* in/out
background: u32 // DWORD
) callconv(std.os.windows.WINAPI) i32;proc GdipCreateHBITMAPFromBitmap(
bitmap: ptr GpBitmap, # GpBitmap* in/out
hbmReturn: pointer, # HBITMAP* in/out
background: uint32 # DWORD
): int32 {.importc: "GdipCreateHBITMAPFromBitmap", stdcall, dynlib: "gdiplus.dll".}pragma(lib, "gdiplus");
extern(Windows)
int GdipCreateHBITMAPFromBitmap(
GpBitmap* bitmap, // GpBitmap* in/out
void* hbmReturn, // HBITMAP* in/out
uint background // DWORD
);ccall((:GdipCreateHBITMAPFromBitmap, "gdiplus.dll"), stdcall, Int32,
(Ptr{GpBitmap}, Ptr{Cvoid}, UInt32),
bitmap, hbmReturn, background)
# bitmap : GpBitmap* in/out -> Ptr{GpBitmap}
# hbmReturn : HBITMAP* in/out -> Ptr{Cvoid}
# background : DWORD -> UInt32
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t GdipCreateHBITMAPFromBitmap(
void* bitmap,
void* hbmReturn,
uint32_t background);
]]
local gdiplus = ffi.load("gdiplus")
-- gdiplus.GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background)
-- bitmap : GpBitmap* in/out
-- hbmReturn : HBITMAP* in/out
-- background : DWORD
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('gdiplus.dll');
const GdipCreateHBITMAPFromBitmap = lib.func('__stdcall', 'GdipCreateHBITMAPFromBitmap', 'int32_t', ['void *', 'void *', 'uint32_t']);
// GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background)
// bitmap : GpBitmap* in/out -> 'void *'
// hbmReturn : HBITMAP* in/out -> 'void *'
// background : DWORD -> 'uint32_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("gdiplus.dll", {
GdipCreateHBITMAPFromBitmap: { parameters: ["pointer", "pointer", "u32"], result: "i32" },
});
// lib.symbols.GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background)
// bitmap : GpBitmap* in/out -> "pointer"
// hbmReturn : HBITMAP* in/out -> "pointer"
// background : DWORD -> "u32"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t GdipCreateHBITMAPFromBitmap(
void* bitmap,
void* hbmReturn,
uint32_t background);
C, "gdiplus.dll");
// $ffi->GdipCreateHBITMAPFromBitmap(bitmap, hbmReturn, background);
// bitmap : GpBitmap* in/out
// hbmReturn : HBITMAP* in/out
// background : DWORD
// 構造体/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 Gdiplus extends StdCallLibrary {
Gdiplus INSTANCE = Native.load("gdiplus", Gdiplus.class);
int GdipCreateHBITMAPFromBitmap(
Pointer bitmap, // GpBitmap* in/out
Pointer hbmReturn, // HBITMAP* in/out
int background // DWORD
);
}@[Link("gdiplus")]
lib Libgdiplus
fun GdipCreateHBITMAPFromBitmap = GdipCreateHBITMAPFromBitmap(
bitmap : GpBitmap*, # GpBitmap* in/out
hbmReturn : Void*, # HBITMAP* in/out
background : UInt32 # DWORD
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef GdipCreateHBITMAPFromBitmapNative = Int32 Function(Pointer<Void>, Pointer<Void>, Uint32);
typedef GdipCreateHBITMAPFromBitmapDart = int Function(Pointer<Void>, Pointer<Void>, int);
final GdipCreateHBITMAPFromBitmap = DynamicLibrary.open('gdiplus.dll')
.lookupFunction<GdipCreateHBITMAPFromBitmapNative, GdipCreateHBITMAPFromBitmapDart>('GdipCreateHBITMAPFromBitmap');
// bitmap : GpBitmap* in/out -> Pointer<Void>
// hbmReturn : HBITMAP* in/out -> Pointer<Void>
// background : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function GdipCreateHBITMAPFromBitmap(
bitmap: Pointer; // GpBitmap* in/out
hbmReturn: Pointer; // HBITMAP* in/out
background: DWORD // DWORD
): Integer; stdcall;
external 'gdiplus.dll' name 'GdipCreateHBITMAPFromBitmap';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "GdipCreateHBITMAPFromBitmap"
c_GdipCreateHBITMAPFromBitmap :: Ptr () -> Ptr () -> Word32 -> IO Int32
-- bitmap : GpBitmap* in/out -> Ptr ()
-- hbmReturn : HBITMAP* in/out -> Ptr ()
-- background : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let gdipcreatehbitmapfrombitmap =
foreign "GdipCreateHBITMAPFromBitmap"
((ptr void) @-> (ptr void) @-> uint32_t @-> returning int32_t)
(* bitmap : GpBitmap* in/out -> (ptr void) *)
(* hbmReturn : HBITMAP* in/out -> (ptr void) *)
(* background : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library gdiplus (t "gdiplus.dll"))
(cffi:use-foreign-library gdiplus)
(cffi:defcfun ("GdipCreateHBITMAPFromBitmap" gdip-create-hbitmapfrom-bitmap :convention :stdcall) :int32
(bitmap :pointer) ; GpBitmap* in/out
(hbm-return :pointer) ; HBITMAP* in/out
(background :uint32)) ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $GdipCreateHBITMAPFromBitmap = Win32::API::More->new('gdiplus',
'int GdipCreateHBITMAPFromBitmap(LPVOID bitmap, HANDLE hbmReturn, DWORD background)');
# my $ret = $GdipCreateHBITMAPFromBitmap->Call($bitmap, $hbmReturn, $background);
# bitmap : GpBitmap* in/out -> LPVOID
# hbmReturn : HBITMAP* in/out -> HANDLE
# background : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
使用する型