5

このデバイスでスキャンされた指紋をキャプチャしようとしています-> http://www.nitgen.com/eng/product/finkey.html

指紋をスキャンして、バイナリ データを正常に保存できました。画像ボックスに指紋を表示することもできます。ただし、画像ボックスに表示されている指紋を保存しようとすると、画像ボックスの画像が null であるというエラーが表示されます。

以下は、指紋をキャプチャして画像ボックスから画像を保存する私のコードです。

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 が使用していないため、明らかに何も起きていません。

更新: これは私がやったことです:

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...");
            }
        }
4

1 に答える 1

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

ウィンドウ ハンドルを指紋スキャナーに渡しました。これは、描画できるウィンドウについてネイティブ コードのチャンクに伝える一般的な方法です。これは通常、ウィンドウ プロシージャをサブクラス化して WM_PAINT 要求に応答します。たとえば、NativeWindow.WndProc() と同じ考え方です。

ただし、Image プロパティは役に立たないことが暗示されています。そのネイティブ コードは、これが PictureBox コントロールであり、Image プロパティがあることを認識していません。コントロール用に作成されたネイティブ ウィンドウについてのみ認識します。

画像を保存するオプションについては、API を調べてください。これは利用できるはずです。そうでない場合は、最初に画像ボックスの DrawToBitmap() メソッドを使用して保存します。スキャナーが WM_PRINT メッセージ ハンドラーを実装している場合、これは機能する可能性があります。それがうまくいかない場合、他の唯一のバックアップ計画は、Graphics.CopyFromScreen() を使用することです。ウィンドウがフォアグラウンドにある限り、これは常に機能します。キーボードの PrtSc ボタンを使用する場合と同様のスクリーン ショット。

于 2013-01-06T14:14:44.510 に答える