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