在OnCaptured
事件中,您从Fiv
en获取图像数据Data.Views
:
注意:pbFingerprint
是一个图片框,其中将显示图像。
private void enrollment_OnCaptured(EnrollmentControl enrollmentControl, CaptureResult captureResult, int fingerPosition)
{
if (captureResult.ResultCode == Constants.ResultCode.DP_SUCCESS)
{
if (captureResult.Data != null)
{
foreach (Fid.Fiv fiv in captureResult.Data.Views)
{
pbFingerprint.Image = CreateBitmap(fiv.RawImage, fiv.Width, fiv.Height);
}
}
}
}
/// <summary>
/// Create a bitmap from raw data in row/column format.
/// </summary>
/// <param name="bytes"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
private Bitmap CreateBitmap(byte[] bytes, int width, int height)
{
byte[] rgbBytes = new byte[bytes.Length * 3];
for (int i = 0; i <= bytes.Length - 1; i++)
{
rgbBytes[(i * 3)] = bytes[i];
rgbBytes[(i * 3) + 1] = bytes[i];
rgbBytes[(i * 3) + 2] = bytes[i];
}
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
for (int i = 0; i <= bmp.Height - 1; i++)
{
IntPtr p = new IntPtr(data.Scan0.ToInt64() + data.Stride * i);
System.Runtime.InteropServices.Marshal.Copy(rgbBytes, i * bmp.Width * 3, p, bmp.Width * 3);
}
bmp.UnlockBits(data);
return bmp;
}