private void btnDownload_Click(object sender, EventArgs e) { try { if (UpdateSensorSettings()) { IntPtr dataBuffer; uint dataBufferSize; Zfm20Fingerprint.ZfmStatus downloadStatus = _zfmSensor.GetFingerprintBuffer(out dataBuffer, out dataBufferSize); if (downloadStatus == Zfm20Fingerprint.ZfmStatus.ZsSuccessful) { if (dataBufferSize > 0) { // Create output bitmap buffer object. Bitmap outputImage = new Bitmap(ImageWidth, ImageHeight); byte[] colorBuffer = new byte[dataBufferSize]; int bufferPos = 0; Marshal.Copy(dataBuffer, colorBuffer, 0, (int)(dataBufferSize - 1)); // Paint bitmap buffer with received data buffer content. for (int yPos = 0; yPos < ImageHeight; yPos++) { for (int xPos = 0; xPos < ImageWidth; xPos++) { outputImage.SetPixel(xPos, yPos, Color.FromArgb(colorBuffer[bufferPos], colorBuffer[bufferPos], colorBuffer[bufferPos])); bufferPos++; } } // Flush data buffer and show bitmap on UI. _zfmSensor.FreeFingerprintBuffer(ref dataBuffer); imgPreview.Image = outputImage; } else { MessageBox.Show(@"Fingerprint image data is not available from the sensor library.", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { MessageBox.Show(ZfmStatusToString(downloadStatus), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btScan_Click(object sender, EventArgs e) { try { if (radioRight.Checked || radioLeft.Checked) { if (_zfmSensor == null) { MessageBox.Show("กรุณาเลือกพอร์ตก่อนทำการสแกน", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string msgText = _zfmSensor.IsAvailable() ? @"Fingerprint sensor is available." : "Fingerprint sensor is not available.\nCheck sensor configuration options."; if (msgText != null) { //MessageBox.Show(msgText, Text, MessageBoxButtons.OK, MessageBoxIcon.Information); if (_zfmSensor.IsAvailable() != true) { MessageBox.Show("พอร์ตไม่ถูกต้อง", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Zfm20Fingerprint.ZfmStatus captureStatus = _zfmSensor.Capture(); if (captureStatus != Zfm20Fingerprint.ZfmStatus.ZsSuccessful) { //MessageBox.Show(ZfmStatusToString(captureStatus), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { IntPtr dataBuffer; uint dataBufferSize; Zfm20Fingerprint.ZfmStatus downloadStatus = _zfmSensor.GetFingerprintBuffer(out dataBuffer, out dataBufferSize); if (downloadStatus == Zfm20Fingerprint.ZfmStatus.ZsSuccessful) { if (dataBufferSize > 0) { // Create output bitmap buffer object. Bitmap outputImage = new Bitmap(ImageWidth, ImageHeight); byte[] colorBuffer = new byte[dataBufferSize]; int bufferPos = 0; Marshal.Copy(dataBuffer, colorBuffer, 0, (int)(dataBufferSize - 1)); // Paint bitmap buffer with received data buffer content. for (int yPos = 0; yPos < ImageHeight; yPos++) { for (int xPos = 0; xPos < ImageWidth; xPos++) { outputImage.SetPixel(xPos, yPos, Color.FromArgb(colorBuffer[bufferPos], colorBuffer[bufferPos], colorBuffer[bufferPos])); bufferPos++; } } // Flush data buffer and show bitmap on UI. _zfmSensor.FreeFingerprintBuffer(ref dataBuffer); Bitmap bmp = new Bitmap(outputImage); bmp.RotateFlip(RotateFlipType.Rotate180FlipNone); pictureBox_Finger.Image = bmp; byte[] gg = Relm.Converters.Converter.ToByteArray(pictureBox_Finger.Image); base64String = Convert.ToBase64String(gg); Console.WriteLine(base64String); } } } } } else { MessageBox.Show("กรุณาเลือกหมายเลขพอร์ต"); } } else { MessageBox.Show("กรุณาเลือกลักษณะลายนิ้วมือ", Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show(ex.Message, Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }