Delphi 从回调函数的参数获取值

Delphi 从回调函数的参数获取值,delphi,dll,biometrics,Delphi,Dll,Biometrics,我用的是一个。我将标题转换为delphi来使用dll 它看起来像这样: const {VrBio_EventType} VRBIO_CAPTURE_EVENT_UNPLUG = $001; {Fingerprint scanner unplugged from the computer.} VRBIO_CAPTURE_EVENT_PLUG = $002; {Fingerprint scanner plugged on the c

我用的是一个。我将标题转换为delphi来使用dll

它看起来像这样:

const
{VrBio_EventType}
  VRBIO_CAPTURE_EVENT_UNPLUG               = $001; {Fingerprint scanner unplugged from the computer.}
  VRBIO_CAPTURE_EVENT_PLUG                 = $002; {Fingerprint scanner plugged on the computer.}
  VRBIO_CAPTURE_EVENT_REMOVED              = $004; {Finger removed from the fingerprint scanner.}
  VRBIO_CAPTURE_EVENT_PLACED               = $008; {Finger placed on the fingerprint scanner.}
  VRBIO_CAPTURE_EVENT_IMAGE_FRAME          = $10;  {A fingerprint frame was captured on the fingerprint scanner.}
  VRBIO_CAPTURE_EVENT_IMAGE_CAPTURED       = $020; {A fingerprint image was captured on the fingerprint scanner.}
  VRBIO_CAPTURE_EVENT_FAKE_FINGER_DETECTED = $400; {A false finger has been detected on the sensor}
  VRBIO_CAPTURE_EVENT_FAKE_FINGER_REMOVED  = $800; {A false finger has been removed from the sensor}

type

(* Stores the parameters of the ISO 19794-4 image format. @see VGetReaderProperties @see VrBio_ReaderProperty 
typedef struct
{
    /** @see VrBio_ISO197944CompressionMode*/
    int compressionMode;
    /** @see VrBio_ISO197944ImpressionType*/
    int impressionType;
    /** @see VrBio_ISO197944FingerPosition*/    
    int fingerPosition;

}VrBio_ISO197944Parameters;
*)

  PISO197944Parameters = ^TISO197944Parameters;
  TISO197944Parameters = record
      compressionMode: Integer; { @see VrBio_ISO197944CompressionMode}
      impressionType: Integer;  { @see VrBio_ISO197944ImpressionType}
      fingerPosition: Integer;  { @see VrBio_ISO197944FingerPosition}
  end;

(* Represents a biometric image. @see VrBio_CaptureEventCallback \ref VSyncCapture 
struct VrBio_BiometricImage
{
  /** Image width.*/
  int width;
  /**Image height*/
  int height;
  /**Image resolution in dpi. For the obsolete functions, use pixels/cm.*/
  int resolution;
  /**Number of channels in the image. Fingerprint images should always be grayscale, so this value is always 1.*/
  int channels;
  /**Biometric modality. 
  * Always use VRBIO_BIOMETRIC_MODALITY_FINGERPRINT. 
  * \ref VrBio_BiometricModality.
  */
  int biometricModality;
  /**Scanner type. 
  * \ref VrBio_ScannerType.
  */
  int scannerType;
  /**Formato de imagem: Formato da imagem.
  *\ ref VrBio_ImageFormat.*/
  int imageFormat;
  /**Size of the buffer*/
  int bufferSize;
  /**Compression rate. Valid for images that allow compression.
  * \ref VrBio_CompressionRate
  */
  int compressionRate; 
 /**Quality of the fingerprint image. 
  * \ref VrBio_FingerQuality
  */
  int fingerQuality;

  /** Only valid if the image if imageFormat is \ref VrBio_ImageFormat::VRBIO_IMAGEFORMAT_ISO19794_4 
  *\ref VrBio_ISO197944Parameters
  */
  VrBio_ISO197944Parameters* ISO197944_parameters;

  /** Buffer storing the pixels of the image.
    The position(x,y,c) of a pixel is y*width*channels+x*channels+c.
  */
  unsigned char* buffer;

  /**Reserved for future use*/
  void* reserved;
};

typedef struct VrBio_BiometricImage VrBio_BiometricImage;
*)
  PBiometricImage = ^TBiometricImage;
  TBiometricImage = record
    width: Integer;                             { Image width. }
    height: Integer;                            { Image height }
    resolution: Integer;                        { Image resolution in dpi. For the obsolete functions, use pixels/cm.}
    channels: Integer;                          { Number of channels in the image. Fingerprint images should always be grayscale, so this value is always 1. }
    biometricModality: Integer;                 { Biometric modality. Always use VRBIO_BIOMETRIC_MODALITY_FINGERPRINT. \ref VrBio_BiometricModality. }
    scannerType: Integer;                       { Scanner type. \ref VrBio_ScannerType. }
    imageFormat: Integer;                       { Formato de imagem: Formato da imagem. \ ref VrBio_ImageFormat. }
    bufferSize: Integer;                        { Size of the buffer }
    compressionRate: Integer;                   { Compression rate. Valid for images that allow compression. \ref VrBio_CompressionRate }
    fingerQuality: Integer;                     { Quality of the fingerprint image. \ref VrBio_FingerQuality }
    ISO197944_parameters: PISO197944Parameters; { Only valid if the image if imageFormat is \ref VrBio_ImageFormat::VRBIO_IMAGEFORMAT_ISO19794_4 \ref VrBio_ISO197944Parameters }
    buffer: PByte;                              { Buffer storing the pixels of the image. The position(x,y,c) of a pixel is y*width*channels+x*channels+c. }
    reserved: Pointer;                          { Reserved for future use }
  end;

(*
#include "VTypes.h"

#ifdef WIN32
#define DLLIMPORT extern "C" __declspec(dllimport) int __stdcall
#else
#define DLLIMPORT extern "C"
#endif
*)

{ Callback function that receives events..
typedef void (*VrBio_CaptureEventCallback) (
                   int  eventType, 
            const char* readerName, 
  VrBio_BiometricImage* image, 
            const void* userData)
}
  TCaptureEventCallback = procedure(eventType: Integer; readerName: PAnsiChar; image: PBiometricImage; userData: Pointer); stdcall;

{ Function responsible for initializing the SDK. This function MUST be called before calling any other method, except \ref VInstallLicense
  DLLIMPORT  VStartSDK(VrBio_CaptureEventCallback eventCallback);
}
  function VStartSDK(eventCallback: TCaptureEventCallback): Integer; stdcall;

{ Function responsible for finalizing the SDK. This function should be called when the SDK is not needed in the application anymore.
  DLLIMPORT  VStopSDK();
}
  function VStopSDK(): Integer; stdcall;

{ Function responsible for starting the capture on a specific fingerprint reader.
  After calling this function, the application is able to receive events.
  DLLIMPORT  VStartReader(const char* readerName);
}
  function VStartReader(readerName: PAnsiChar): Integer; stdcall;
implementation

{$R *.dfm}

procedure EventCallback(eventType: Integer; readerName: PAnsiChar; image: PBiometricImage; userData: Pointer); stdcall;
begin
  case eventType of
    VRBIO_CAPTURE_EVENT_UNPLUG:               Form1.Memo1.Lines.Add('Leitor desconectado!');
    VRBIO_CAPTURE_EVENT_REMOVED:              Form1.Memo1.Lines.Add('Dedo removido!');
    VRBIO_CAPTURE_EVENT_PLACED:               Form1.Memo1.Lines.Add('Dedo detectado!');
    VRBIO_CAPTURE_EVENT_IMAGE_FRAME:          Form1.Memo1.Lines.Add('Frame capturado!');
    VRBIO_CAPTURE_EVENT_IMAGE_CAPTURED:       Form1.Memo1.Lines.Add('Imagem capturada!');
    VRBIO_CAPTURE_EVENT_FAKE_FINGER_DETECTED: Form1.Memo1.Lines.Add('Dedo falso detectado!');
    VRBIO_CAPTURE_EVENT_FAKE_FINGER_REMOVED:  Form1.Memo1.Lines.Add('Dedo falso removido!');

    VRBIO_CAPTURE_EVENT_PLUG:
    begin
      VStartReader(readerName);
      Form1.Memo1.Lines.Add('Leitor conectado!');
    end;

  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  VStartSDK(EventCallback);
end;
使用它看起来像这样:

const
{VrBio_EventType}
  VRBIO_CAPTURE_EVENT_UNPLUG               = $001; {Fingerprint scanner unplugged from the computer.}
  VRBIO_CAPTURE_EVENT_PLUG                 = $002; {Fingerprint scanner plugged on the computer.}
  VRBIO_CAPTURE_EVENT_REMOVED              = $004; {Finger removed from the fingerprint scanner.}
  VRBIO_CAPTURE_EVENT_PLACED               = $008; {Finger placed on the fingerprint scanner.}
  VRBIO_CAPTURE_EVENT_IMAGE_FRAME          = $10;  {A fingerprint frame was captured on the fingerprint scanner.}
  VRBIO_CAPTURE_EVENT_IMAGE_CAPTURED       = $020; {A fingerprint image was captured on the fingerprint scanner.}
  VRBIO_CAPTURE_EVENT_FAKE_FINGER_DETECTED = $400; {A false finger has been detected on the sensor}
  VRBIO_CAPTURE_EVENT_FAKE_FINGER_REMOVED  = $800; {A false finger has been removed from the sensor}

type

(* Stores the parameters of the ISO 19794-4 image format. @see VGetReaderProperties @see VrBio_ReaderProperty 
typedef struct
{
    /** @see VrBio_ISO197944CompressionMode*/
    int compressionMode;
    /** @see VrBio_ISO197944ImpressionType*/
    int impressionType;
    /** @see VrBio_ISO197944FingerPosition*/    
    int fingerPosition;

}VrBio_ISO197944Parameters;
*)

  PISO197944Parameters = ^TISO197944Parameters;
  TISO197944Parameters = record
      compressionMode: Integer; { @see VrBio_ISO197944CompressionMode}
      impressionType: Integer;  { @see VrBio_ISO197944ImpressionType}
      fingerPosition: Integer;  { @see VrBio_ISO197944FingerPosition}
  end;

(* Represents a biometric image. @see VrBio_CaptureEventCallback \ref VSyncCapture 
struct VrBio_BiometricImage
{
  /** Image width.*/
  int width;
  /**Image height*/
  int height;
  /**Image resolution in dpi. For the obsolete functions, use pixels/cm.*/
  int resolution;
  /**Number of channels in the image. Fingerprint images should always be grayscale, so this value is always 1.*/
  int channels;
  /**Biometric modality. 
  * Always use VRBIO_BIOMETRIC_MODALITY_FINGERPRINT. 
  * \ref VrBio_BiometricModality.
  */
  int biometricModality;
  /**Scanner type. 
  * \ref VrBio_ScannerType.
  */
  int scannerType;
  /**Formato de imagem: Formato da imagem.
  *\ ref VrBio_ImageFormat.*/
  int imageFormat;
  /**Size of the buffer*/
  int bufferSize;
  /**Compression rate. Valid for images that allow compression.
  * \ref VrBio_CompressionRate
  */
  int compressionRate; 
 /**Quality of the fingerprint image. 
  * \ref VrBio_FingerQuality
  */
  int fingerQuality;

  /** Only valid if the image if imageFormat is \ref VrBio_ImageFormat::VRBIO_IMAGEFORMAT_ISO19794_4 
  *\ref VrBio_ISO197944Parameters
  */
  VrBio_ISO197944Parameters* ISO197944_parameters;

  /** Buffer storing the pixels of the image.
    The position(x,y,c) of a pixel is y*width*channels+x*channels+c.
  */
  unsigned char* buffer;

  /**Reserved for future use*/
  void* reserved;
};

typedef struct VrBio_BiometricImage VrBio_BiometricImage;
*)
  PBiometricImage = ^TBiometricImage;
  TBiometricImage = record
    width: Integer;                             { Image width. }
    height: Integer;                            { Image height }
    resolution: Integer;                        { Image resolution in dpi. For the obsolete functions, use pixels/cm.}
    channels: Integer;                          { Number of channels in the image. Fingerprint images should always be grayscale, so this value is always 1. }
    biometricModality: Integer;                 { Biometric modality. Always use VRBIO_BIOMETRIC_MODALITY_FINGERPRINT. \ref VrBio_BiometricModality. }
    scannerType: Integer;                       { Scanner type. \ref VrBio_ScannerType. }
    imageFormat: Integer;                       { Formato de imagem: Formato da imagem. \ ref VrBio_ImageFormat. }
    bufferSize: Integer;                        { Size of the buffer }
    compressionRate: Integer;                   { Compression rate. Valid for images that allow compression. \ref VrBio_CompressionRate }
    fingerQuality: Integer;                     { Quality of the fingerprint image. \ref VrBio_FingerQuality }
    ISO197944_parameters: PISO197944Parameters; { Only valid if the image if imageFormat is \ref VrBio_ImageFormat::VRBIO_IMAGEFORMAT_ISO19794_4 \ref VrBio_ISO197944Parameters }
    buffer: PByte;                              { Buffer storing the pixels of the image. The position(x,y,c) of a pixel is y*width*channels+x*channels+c. }
    reserved: Pointer;                          { Reserved for future use }
  end;

(*
#include "VTypes.h"

#ifdef WIN32
#define DLLIMPORT extern "C" __declspec(dllimport) int __stdcall
#else
#define DLLIMPORT extern "C"
#endif
*)

{ Callback function that receives events..
typedef void (*VrBio_CaptureEventCallback) (
                   int  eventType, 
            const char* readerName, 
  VrBio_BiometricImage* image, 
            const void* userData)
}
  TCaptureEventCallback = procedure(eventType: Integer; readerName: PAnsiChar; image: PBiometricImage; userData: Pointer); stdcall;

{ Function responsible for initializing the SDK. This function MUST be called before calling any other method, except \ref VInstallLicense
  DLLIMPORT  VStartSDK(VrBio_CaptureEventCallback eventCallback);
}
  function VStartSDK(eventCallback: TCaptureEventCallback): Integer; stdcall;

{ Function responsible for finalizing the SDK. This function should be called when the SDK is not needed in the application anymore.
  DLLIMPORT  VStopSDK();
}
  function VStopSDK(): Integer; stdcall;

{ Function responsible for starting the capture on a specific fingerprint reader.
  After calling this function, the application is able to receive events.
  DLLIMPORT  VStartReader(const char* readerName);
}
  function VStartReader(readerName: PAnsiChar): Integer; stdcall;
implementation

{$R *.dfm}

procedure EventCallback(eventType: Integer; readerName: PAnsiChar; image: PBiometricImage; userData: Pointer); stdcall;
begin
  case eventType of
    VRBIO_CAPTURE_EVENT_UNPLUG:               Form1.Memo1.Lines.Add('Leitor desconectado!');
    VRBIO_CAPTURE_EVENT_REMOVED:              Form1.Memo1.Lines.Add('Dedo removido!');
    VRBIO_CAPTURE_EVENT_PLACED:               Form1.Memo1.Lines.Add('Dedo detectado!');
    VRBIO_CAPTURE_EVENT_IMAGE_FRAME:          Form1.Memo1.Lines.Add('Frame capturado!');
    VRBIO_CAPTURE_EVENT_IMAGE_CAPTURED:       Form1.Memo1.Lines.Add('Imagem capturada!');
    VRBIO_CAPTURE_EVENT_FAKE_FINGER_DETECTED: Form1.Memo1.Lines.Add('Dedo falso detectado!');
    VRBIO_CAPTURE_EVENT_FAKE_FINGER_REMOVED:  Form1.Memo1.Lines.Add('Dedo falso removido!');

    VRBIO_CAPTURE_EVENT_PLUG:
    begin
      VStartReader(readerName);
      Form1.Memo1.Lines.Add('Leitor conectado!');
    end;

  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  VStartSDK(EventCallback);
end;
我的问题是:

我可以使用该应用程序获取
插拔
拔出
放置
事件,但当我获取捕获的
图像
事件时,我有一个访问权限。 在工作的事件中,
EventCallback
参数图像为
nil
。TBiometricImage记录转换是否正确

如何将TBiometricImage缓冲区转换为TBitmap并在TImage中显示捕获的图像

当我拍摄到事件的图像时,我有一个访问权限。在正在工作的事件中,EventCallback参数映像为nil。TBiometricImage记录转换是否正确

单独的字段声明为良好,但请仔细检查Delphi记录的对齐方式和填充方式是否与C/C++中的结构使用的对齐方式和填充方式相同

此外,更重要的是,C/C++中的
VrBio\u CaptureEventCallback
typedef是在没有指定任何调用约定的情况下声明的,因此它将使用编译器的默认约定,通常是
\uuuuuu cdecl
,而不是
\uu stdcall
(可以在编译器设置中配置)。在Delphi中,您声明了
TCaptureEventCallback
以使用
stdcall
而不是
cdecl
。您必须确保正确地匹配调用约定(导出的DLL函数确实使用
stdcall
,因此您在那里没有问题)

如何将TBiometricImage缓冲区转换为TBitmap并在TImage中显示捕获的图像

SDK文档没有解释如何处理各种图像格式。但是,只要查看struct声明,
buffer
字段就指向实际图像数据,
imageFormat
字段指示该数据的格式(有一个
VrBio_imageFormat
枚举,您还没有翻译)。因此,您必须首先查看
imageFormat
,以了解如何解释
缓冲区

我确实看到一个
VConvertImage()
函数可用。因此,您应该能够将图像转换为BMP格式(如果尚未转换)。根据SDK中的示例,看起来
buffer
数据可能是标准的BMP文件格式,因此您可以尝试将
buffer
复制到
TMemoryStream
中,然后使用
TBitmap.LoadFromStream()
方法

还有GIF和JPG图像格式可用,如果您想显示扫描的GIF/JPG图像而不必首先将其转换为BMP,则可以分别通过
tgiImage
TJPEGImage
处理,甚至可以通过
TWICImage
处理。还有一种可用的原始图像格式(显然您的图像正在使用),但是没有标准的VCL
TGraphic
类来处理原始图像,但是如果您四处看看,我认为可能会有一些第三方类


否则,如果需要,您可以尝试将图像数据转换为BMP,然后将
缓冲区
传递给Win32 API
CreateBitmap/Indirect()
CreateDibSection()
函数,然后将生成的
HBITMAP
分配给
TBitmap。如果成功,请处理
属性。

感谢您的回答。关于呼叫会议你说得对,我现在可以捕获所有事件了!事实上,还有其他一些我没有提到的结构<代码>VrBio_图像格式
如下所示:
TImageFormat=(VRBIO_IMAGEFORMAT_未知,VRBIO_IMAGEFORMAT_原始,VRBIO_IMAGEFORMAT_BMP,VRBIO_IMAGEFORMAT_WSQ,VRBIO_IMAGEFORMAT_ISO19794_4,VRBIO_IMAGEFORMAT_JPEG,VRBIO_IMAGEFORMAT_TIFF,VRBIO_IMAGEFORMAT_PNG,VRBIO_IMAGEFORMAT_GIF);
我得到的格式是
RAW
。同样,如果没有看到SDK文档,这里的任何人都无法知道任何给定图像类型的像素数据是什么样子的。可能
RAW
数据是RGB颜色,或者可能数据是实际的。感谢您所做的一切,我可以使用
VConvertImage()显示图像