我正在 try catch 此设备扫描的指纹-> http://www.nitgen.com/eng/product/finkey.html

我能够扫描指纹并成功保存二进制数据。我还可以在图片框中显示指纹。但是,当我尝试保存在图片框中显示的指纹时,出现错误,即图片框的图像为空。

下面是我捕获指纹并从图片框保存图像的代码。

public class Form1 : System.Windows.Forms.Form
{
    public NBioBSPCOMLib.NBioBSP objNBioBSP;
    public NBioBSPCOMLib.IExtraction objExtraction;
    private PictureBox pictureExtWnd;

    private void Form1_Load(object sender, System.EventArgs e)
    {
        // Create NBioBSP object
        objNBioBSP = new NBioBSPCOMLib.NBioBSPClass();
        objExtraction = (NBioBSPCOMLib.IExtraction)objNBioBSP.Extraction;
        pictureExtWnd.Image = new Bitmap(pictureExtWnd.Width, pictureExtWnd.Height);
    }

    private void buttonEnroll_Click(object sender, System.EventArgs e)
    {
        //tell NBIO to not display their fingerprint scanning window
        objExtraction.WindowStyle = NBioBSPType.WINDOW_STYLE.INVISIBLE;

        //set the color of the fingerprint captured
        objExtraction.FPForeColor = "000000";

        //set the color of the background where the fingerprint will be displayed
        objExtraction.FPBackColor = "FFFFFF";

        //tell NBIO that the scanned fingerprint will be displayed in the picturebox
        //by giving the handle control to NBIO
        objExtraction.FingerWnd = pictureExtWnd.Handle.ToInt32();

        //start scanning the fingerprint. This is also where the fingerprint
        //is displayed in the picturebox.
        objExtraction.Capture((int)NBioBSPType.FIR_PURPOSE.VERIFY);

        //if there's no problem while scanning the fingerprint, save the fingerprint image
        if (objExtraction.ErrorCode == NBioBSPError.NONE)
        {
            string fileName = RandomString.GetRandomString(16, true) + ".bmp";

            using (SaveFileDialog sfdlg = new SaveFileDialog())
            {
                sfdlg.Title = "Save Dialog";
                sfdlg.Filter = "Bitmap Images (*.bmp)|*.bmp|All files(*.*)|*.*";
                if (sfdlg.ShowDialog(this) == DialogResult.OK)
                {
                    pictureExtWnd.Image.Save(sfdlg.FileName, ImageFormat.Bmp);
                    MessageBox.Show("FingerPrint Saved Successfully.");
                }
            }
        }
        else
        {
            MessageBox.Show("FingerPrint Saving Failed!");
        }
    }
}

我尝试将其封闭在里面
using(Graphics g = new Graphics)
{
    objExtraction.Capture((int)NBioBSPType.FIR_PURPOSE.VERIFY);
}

因为我已经读过,在对图像进行编辑时,需要使用图形。但由于api没有使用我实例化的图形对象,因此显然没有任何 react 。

更新:
这就是我最终要做的事情:
using (SaveFileDialog sfdlg = new SaveFileDialog())
        {
            sfdlg.Title = "Save Dialog";
            sfdlg.Filter = "Bitmap Images (*.bmp)|*.bmp|All files(*.*)|*.*";
            if (sfdlg.ShowDialog(this) == DialogResult.OK)
            {
                Graphics gfx = this.pictureExtWnd.CreateGraphics();
                Bitmap bmp = new Bitmap(this.pictureExtWnd.Width, this.pictureExtWnd.Height);
                this.pictureExtWnd.DrawToBitmap(bmp, new Rectangle(0, 0, this.pictureExtWnd.Width, this.pictureExtWnd.Height));
                bmp.Save(sfdlg.FileName, ImageFormat.Bmp);

                gfx.Dispose();
                //pictureExtWnd.Image.Save(sfdlg.FileName, ImageFormat.Bmp);
                MessageBox.Show("Saved Successfully...");
            }
        }

最佳答案

    objExtraction.FingerWnd = pictureExtWnd.Handle.ToInt32();

您将窗口 handle 传递给了指纹扫描仪。这是告诉 native 代码块有关可绘制窗口的一种常见方法。通常,它将子类化窗口过程以响应WM_PAINT请求,例如,与NativeWindow.WndProc()相同。

但是,暗含的是Image属性是无用的。该本地代码不知道这是一个PictureBox控件,并且不具有Image属性。它只知道为控件创建的 native 窗口。

一定要在api中查找保存图像的选项,该选项应该可用。如果不是,则保存图片的第一张照片是使用图片框的DrawToBitmap()方法。如果扫描程序实现WM_PRINT消息处理程序,则可能有效。如果那不起作用,那么您唯一的其他备份计划是使用Graphics.CopyFromScreen()。只要窗口在前景中,它将始终有效。屏幕截图类似于在键盘上使用PrtSc按钮。

09-30 14:05
查看更多