Как решить проблему "произошла ошибка: исключение из HRESULT: 0xffffff8"C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Как решить проблему "произошла ошибка: исключение из HRESULT: 0xffffff8"

Сообщение Anonymous »

Я использую Visual Studio и пытаюсь проверить шаблон отпечатка пальца и создать запись, соответствующую отпечатку пальца, который я отсканировал с помощью считывателя отпечатков пальцев uareu. Полный код проверки приведен ниже. Пожалуйста, помогите мне найти эту ошибку, так как я только увлекаюсь программированием на C#
using DPFP;
using DPFP.Capture;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Mysqlx.Notice.Warning.Types;
using System.IO;

namespace ExaminationAuthentication
{
public partial class verificationForm : Form, DPFP.Capture.EventHandler
{

private DPFP.Capture.Capture Capturer;
private DPFP.Verification.Verification Verificator;

public verificationForm()
{
InitializeComponent();
Verificator = new DPFP.Verification.Verification();
}

public void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
{
this.Invoke(new Action(() =>
{
MakeReport("The fingerprint sample was captured. Checking against the database...");
try
{
Process(Sample);
}
catch (Exception ex)
{
MessageBox.Show($"Error during processing: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}));
}

public void OnFingerGone(object Capture, string ReaderSerialNumber)
{
SetStatus("The finger was removed from the fingerprint reader.");
}

public void OnFingerTouch(object Capture, string ReaderSerialNumber)
{
SetStatus("The fingerprint reader was touched.");
}

public void OnReaderConnect(object Capture, string ReaderSerialNumber)
{
SetStatus("The fingerprint reader was connected.");
}

public void OnReaderDisconnect(object Capture, string ReaderSerialNumber)
{
SetStatus("The fingerprint reader was disconnected.");
}

public void OnSampleQuality(object Capture, string ReaderSerialNumber, CaptureFeedback CaptureFeedback)
{
if (CaptureFeedback == DPFP.Capture.CaptureFeedback.Good)
SetStatus("The quality of the fingerprint sample is good.");
else
SetStatus("The quality of the fingerprint sample is poor.");
}

protected void SetStatus(string message)
{
this.Invoke(new Action(delegate ()
{
StatusLabel.Text = message;
}));
}

protected void MakeReport(string message)
{
this.Invoke(new Action(delegate ()
{
StatusText.AppendText(message + "\r\n");
}));
}

private void verificationForm_Load(object sender, EventArgs e)
{
try
{
Capturer = new DPFP.Capture.Capture();
if (Capturer != null)
{
Capturer.EventHandler = this;
MakeReport("Press start capture to start scanning for authentication.");
}
else
{
MakeReport("Cannot initiate capture operation.");
}
}
catch
{
MessageBox.Show("Can't initiate Capture Operation!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

protected virtual void Process(DPFP.Sample Sample)
{
this.Invoke(new Action(() =>
{
Bitmap fingerprint = ConvertSampleToBitmap(Sample);
DrawPicture(fingerprint);

// Extract features from the fingerprint sample
DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);

if (features != null)
{
VerifyFingerprint(features);
}
else
{
MessageBox.Show("The fingerprint quality is poor. Please try again.", "Quality Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}));
}

private DPFP.FeatureSet ExtractFeatures(DPFP.Sample Sample, DPFP.Processing.DataPurpose Purpose)
{
DPFP.Processing.FeatureExtraction extractor = new DPFP.Processing.FeatureExtraction();
DPFP.Capture.CaptureFeedback feedback = DPFP.Capture.CaptureFeedback.None;
DPFP.FeatureSet features = new DPFP.FeatureSet();

try
{
extractor.CreateFeatureSet(Sample, Purpose, ref feedback, ref features);
if (feedback == DPFP.Capture.CaptureFeedback.Good)
{
return features;
}
else
{
MakeReport("The fingerprint sample quality is not sufficient.");
return null;
}
}
catch (Exception ex)
{
MessageBox.Show($"Error extracting features: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}

private void VerifyFingerprint(DPFP.FeatureSet features)
{
string connectionString = "server=localhost;user=root;database=ivs;password=";

using (MySqlConnection connection = new MySqlConnection(connectionString))
{
string query = "SELECT * FROM students";

using (MySqlCommand cmd = new MySqlCommand(query, connection))
{
try
{
connection.Open();
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
byte[] storedFingerprint = (byte[])reader["fingerprint"];
DPFP.Template template = new DPFP.Template();
template.DeSerialize(storedFingerprint);

DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
Verificator.Verify(features, template, ref result);

if (result.Verified)
{
MessageBox.Show("Fingerprint match found! Retrieving user data...");

// Display the user's details
DisplayUserData(reader);
return;
}
}
}

MessageBox.Show("No matching fingerprint found in the database.", "Authentication Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
catch (Exception ex)
{
MessageBox.Show($"An error occurred: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

private void DisplayUserData(MySqlDataReader reader)
{
// Assuming you have text boxes and other controls named accordingly on your form
txtSurname.Text = reader["surname"].ToString();
txtOthernames.Text = reader["othernames"].ToString();
txtSex.Text = reader["sex"].ToString();
txtDOB.Value = Convert.ToDateTime(reader["dob"]); // Assuming txtDOB is a DateTimePicker
txtPhoneNumber.Text = reader["phoneNumber"].ToString();
txtEmailAddress.Text = reader["emailAddress"].ToString();
txtResidentialAddress.Text = reader["residentialAddress"].ToString();
txtStateOfOrigin.Text = reader["stateOfOrigin"].ToString();
txtLocalGovernmentArea.Text = reader["localGovernmentArea"].ToString();
txtMatricNumber.Text = reader["matricNumber"].ToString();
txtLevel.Text = reader["level"].ToString();
txtDepartment.Text = reader["department"].ToString();
txtSchool.Text = reader["school"].ToString();

// Convert the timestamp to a DateTime format and display it
txtTimestamp.Text = Convert.ToDateTime(reader["timestamp"]).ToString("yyyy-MM-dd HH:mm:ss");

// Convert the byte array from the database back into an Image for the passport
byte[] passportData = (byte[])reader["passport"];
if (passportData != null && passportData.Length > 0)
{
using (MemoryStream ms = new MemoryStream(passportData))
{
pbPassport.Image = Image.FromStream(ms); // Display the passport image in the PictureBox
}
}

// Display a success message
MessageBox.Show("User data retrieved successfully and populated in the form.", "Data Retrieved", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

protected Bitmap ConvertSampleToBitmap(DPFP.Sample Sample)
{
DPFP.Capture.SampleConversion Convertor = new DPFP.Capture.SampleConversion();
Bitmap bitmap = null;
try
{
Convertor.ConvertToPicture(Sample, ref bitmap);
}
catch (Exception ex)
{
MessageBox.Show($"Error converting sample to bitmap: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return bitmap;
}

private void DrawPicture(Bitmap bitmap)
{
pbFingerprint.Image = new Bitmap(bitmap, pbFingerprint.Size);
}

private byte[] SampleToByteArray(DPFP.Sample sample)
{
DPFP.Capture.SampleConversion converter = new DPFP.Capture.SampleConversion();
Bitmap bitmap = null;
converter.ConvertToPicture(sample, ref bitmap);

using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
}

private void verificationForm_FormClosed(object sender, FormClosedEventArgs e)
{

}

private void btnStopCapture_Click(object sender, EventArgs e)
{
if (Capturer != null)
{
try
{
Capturer.StopCapture();
MakeReport("Stopped scanning the fingerprint.");
}
catch
{
MakeReport("Can't terminate Capture.");
}
}
}

private void btnCaptureFingerprint_Click(object sender, EventArgs e)
{
if (Capturer != null)
{
try
{
Capturer.StartCapture();
MakeReport("Using the fingerprint reader, scan your fingerprint.");
}
catch
{
MakeReport("Can't initiate Capture.");
}
}
}
}
}


Подробнее здесь: https://stackoverflow.com/questions/789 ... 0xfffffff8
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»