gpt4 book ai didi

delphi - 从回调函数的参数中获取值

转载 作者:行者123 更新时间:2023-12-02 08:47:22 24 4
gpt4 key购买 nike

我正在使用biometrics SDK 。我将 header 转换为 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;

我的问题:

我可以使用该应用程序并获取 PlugUnplugPlaced 事件,但是当我获取Image Captured 事件 我有一个访问错误。在正在运行的事件中,EventCallback 参数图像为nil。 TBiometricImage 记录转换是否正确?

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

最佳答案

when I get the Image Captured event I have an acces vilation. In the events that are working the EventCallback parameter image is nil. Is the TBiometricImage record conversion correct?

各个字段都声明得很好,但请仔细检查 Delphi 记录的对齐和填充是否与 C/C++ 中的结构使用的对齐和填充相同。

此外,更重要的是,C/C++ 中的 VrBio_CaptureEventCallback typedef 声明时没有指定任何调用约定,因此它将使用编译器的默认约定,通常为 __cdecl而不是 __stdcall (可以在编译器设置中配置)。在 Delphi 中,您声明了 TCaptureEventCallback 以使用 stdcall 而不是 cdecl。您必须确保正确匹配调用约定(导出的 DLL 函数确实使用 stdcall,因此没问题)。

How can I convert the TBiometricImage buffer to a TBitmap and display the captured image in a TImage?

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

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

还有 GIF 和 JPG 图像格式可用,它们可以分别由 TGIFImageTJPEGImage 处理,甚至可以由 TWICImage 处理,如果您想要显示扫描的 GIF/JPG 图像,而无需先将其转换为 BMP。还有一个可用的 RAW 图像格式(显然你的图像正在使用它),但是没有标准的 VCL TGraphic 类来处理 RAW 图像,但我认为可能存在一些 3rd 方类,如果你环顾四周。

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

关于delphi - 从回调函数的参数中获取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41045589/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com