ルート画像の確保(import版)
Namespace: fvalgcliAssembly: fvalgcli (in fvalgcli.dll) Version: 3.1.0.0 (3.1.0.11)
Syntax
C# |
---|
public static FHANDLE fnFIE_img_root_import_alloc( IntPtr[] adrss, int channels, int type, SIZE_T step, int width, int height ) |
Visual Basic |
---|
Public Shared Function fnFIE_img_root_import_alloc ( adrss As IntPtr(), channels As Integer, type As Integer, step As SIZE_T, width As Integer, height As Integer ) As FHANDLE |
Parameters
- adrss
- Type: array<System..::..IntPtr>[]()[][]
画像メモリのポインタ列。 (チャネル0から順番になった配列で channels パラメータ個分の要素が必要)
- channels
- Type: System..::..Int32
チャネル数(1〜16)
- type
- Type: System..::..Int32
画像種別。f_imgtype に定義された定数を指定。
- step
- Type: fvalgcli..::..SIZE_T
画像ステップ(メモリ横幅:画素サイズ単位) 但し、下記の画像型の場合は単位が変わります。- F_IMG_BIN型の場合:UINTブロック数
- F_IMG_RGBTRIPLE型の場合:バイト単位
- width
- Type: System..::..Int32
画像幅(1以上)
- height
- Type: System..::..Int32
画像高さ(1以上)
Return Value
Type: FHANDLE外部で確保された画像メモリ空間を使用してルート画像を作成し、 確保された画像のハンドルを返します。 ライセンスエラー、未初期化エラー、またはメモリ不足で確保に失敗した場合は IntPtr.Zero を返します。
Examples
C# | Copy |
---|---|
// $Revision: 1.2 $ using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using fvalgcli; namespace TC { public partial class FIE { // Heap API flags const int HEAP_ZERO_MEMORY = 0x00000008; [DllImport("kernel32")] static extern int GetProcessHeap(); [DllImport("kernel32.dll")] public static extern IntPtr HeapAlloc(int hHeap, uint dwFlags, int dwBytes); [DllImport("kernel32.dll")] public static extern bool HeapFree(int hHeap, uint flags, IntPtr block); /// <summary> /// ルート画像の確保(import版). /// </summary> [FvPluginExecute] public void fnFIE_img_root_import_alloc() { FHANDLE hroot = FHANDLE.Zero; int status = (int)f_err.F_ERR_NONE; int type = (int)f_imgtype.F_IMG_UC8; int channels = 3; int step = 640; int width = 640; int height = 480; IntPtr[] imgs = new IntPtr[channels]; int hp = GetProcessHeap(); try { // 画像メモリ空間の確保. for (int ch = 0; ch < channels; ch++) { IntPtr img = HeapAlloc(hp, HEAP_ZERO_MEMORY, width * height); imgs[ch] = img; UCHAR_PTR pb = img; for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { pb[y * step + x] = (byte)((y + x) % 256); } } } // 処理の実行. hroot = api.fnFIE_img_root_import_alloc(imgs, channels, type, step, width, height); Assert.IsTrue(hroot != FHANDLE.Zero, "fnFIE_img_root_import_alloc: エラーが発生しました。"); // 視覚的な確認の為. api.fnFIE_save_bmp(ResultDir + "/fnFIE_img_root_import_alloc.bmp", hroot); // 確認. for (int ch = 0; ch < channels; ch++) { Assert.IsTrue(imgs[ch] == api.fnFIE_img_get_ch_adrs(hroot, ch), "画像アドレスが一致しません。チャンネル{0}", ch); } for (int ch = 0; ch < channels; ch++) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { double dens = 0; status = api.fnFIE_img_get_dens(hroot, ch, x, y, ref dens); Assert.IsTrue(status == (int)f_err.F_ERR_NONE, "fnFIE_img_get_dens: エラーが発生しました。({0})", (f_err)status); if (dens != (byte)((y + x) % 256)) { Assert.IsTrue(false, "値が一致しません。"); break; } } } } } finally { // メモリの開放. for (int ch = 0; ch < channels; ch++) { HeapFree(hp, HEAP_ZERO_MEMORY, imgs[ch]); } // オブジェクトの開放. hroot.Dispose(); } } } } |
Visual Basic | Copy |
---|---|
' $Revision: 1.2 $ Imports System.Collections.Generic Imports System.Text Imports System.Runtime.InteropServices Imports fvalgcli Public Partial Class FIE ' Heap API flags Const HEAP_ZERO_MEMORY As Integer = &H8 <DllImport("kernel32")> _ Private Shared Function GetProcessHeap() As Integer End Function <DllImport("kernel32.dll")> _ Public Shared Function HeapAlloc(hHeap As Integer, dwFlags As UInteger, dwBytes As Integer) As IntPtr End Function <DllImport("kernel32.dll")> _ Public Shared Function HeapFree(hHeap As Integer, flags As UInteger, block As IntPtr) As Boolean End Function ''' <summary> ''' ルート画像の確保(import版). ''' </summary> <FvPluginExecute> _ Public Sub fnFIE_img_root_import_alloc() Dim hroot As FHANDLE = FHANDLE.Zero Dim status As Integer = CInt(f_err.F_ERR_NONE) Dim type As Integer = CInt(f_imgtype.F_IMG_UC8) Dim channels As Integer = 3 Dim [step] As Integer = 640 Dim width As Integer = 640 Dim height As Integer = 480 Dim imgs As IntPtr() = New IntPtr(channels - 1) {} Dim hp As Integer = GetProcessHeap() Try ' 画像メモリ空間の確保. For ch As Integer = 0 To channels - 1 Dim img As IntPtr = HeapAlloc(hp, HEAP_ZERO_MEMORY, width * height) imgs(ch) = img Dim pb As UCHAR_PTR = img For y As Integer = 0 To height - 1 For x As Integer = 0 To width - 1 pb(y * [step] + x) = CByte((y + x) Mod 256) Next Next Next ' 処理の実行. hroot = api.fnFIE_img_root_import_alloc(imgs, channels, type, [step], width, height) Assert.IsTrue(hroot <> FHANDLE.Zero, "fnFIE_img_root_import_alloc: エラーが発生しました。") ' 視覚的な確認の為. api.fnFIE_save_bmp(ResultDir & "/fnFIE_img_root_import_alloc.bmp", hroot) ' 確認. For ch As Integer = 0 To channels - 1 Assert.IsTrue(imgs(ch) = api.fnFIE_img_get_ch_adrs(hroot, ch), "画像アドレスが一致しません。チャンネル{0}", ch) Next For ch As Integer = 0 To channels - 1 For y As Integer = 0 To height - 1 For x As Integer = 0 To width - 1 Dim dens As Double = 0 status = api.fnFIE_img_get_dens(hroot, ch, x, y, dens) Assert.IsTrue(status = CInt(f_err.F_ERR_NONE), "fnFIE_img_get_dens: エラーが発生しました。({0})", CType(status, f_err)) If dens <> CByte((y + x) Mod 256) Then Assert.IsTrue(False, "値が一致しません。") Exit For End If Next Next Next Finally ' メモリの開放. For ch As Integer = 0 To channels - 1 HeapFree(hp, HEAP_ZERO_MEMORY, imgs(ch)) Next ' オブジェクトの開放. hroot.Dispose() End Try End Sub End Class |