/// <summary>
        ///		Converts <see cref="Fid.Fiv"/> instance into new instance of <see cref="Bitmap"/> class.
        /// </summary>
        /// <param name="fingerprintData">
        ///		<see cref="Fid.Fiv"/> data to be converted into <see cref="Bitmap"/> instance.
        ///	</param>
        /// <returns>
        ///		Instance of <see cref="Bitmap"/> class converted from <see cref="Fid.Fiv"/>; returns null if an error has occured.
        /// </returns>
        /// <exception cref="NullReferenceException">
        ///		<paramref name="fingerprintData"> cannot be null. </paramref>
        /// </exception>
        public static Bitmap ToBitmap(this Fid.Fiv fingerprintData)
        {
            // temporary from SDK
            var bmp = new Bitmap(fingerprintData.Width, fingerprintData.Height, DrawImg.PixelFormat.Format24bppRgb);

            DrawImg.BitmapData data = bmp.LockBits(DrawImg.ImageLockMode.WriteOnly);

            try
            {
                byte[] inBytes = fingerprintData.RawImage,
                rgbBytes = new byte[fingerprintData.RawImage.Length * 3];

                for (int i = 0; i < inBytes.Length; ++i)
                {
                    rgbBytes[i * 3 + 0] = inBytes[i];
                    rgbBytes[i * 3 + 1] = inBytes[i];
                    rgbBytes[i * 3 + 2] = inBytes[i];
                }

                for (int i = 0; i < bmp.Height; ++i)
                {
                    Marshal.Copy(rgbBytes, i * bmp.Width * 3, new IntPtr(data.Scan0.ToInt64() + data.Stride * i), bmp.Width * 3);
                }
            }
            catch
            {
                return(null);
            }
            finally
            {
                bmp.UnlockBits(data);
            }

            return(bmp);
        }
예제 #2
0
        public void OnCaptured(CaptureResult captureResult)
        {
            Console.WriteLine(captureResult.ToString());

            Fid.Fiv f      = captureResult.Data.Views[0];
            int     height = f.Height;
            int     width  = f.Width;

            Console.WriteLine(height * width);
            byte[] bytes = f.RawImage;

            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];
            }
            Console.WriteLine(bytes.Length);
            Console.WriteLine("Bytes = " + bytes.Length);

            Bitmap final = new Bitmap(width, height);

            for (int hi = 0; hi < height; hi++)
            {
                for (int wi = 0; wi < width; wi = wi + 3)
                {
                    System.Drawing.Color color = System.Drawing.Color.FromArgb(bytes[hi * width + wi], bytes[hi * width + wi + 1], bytes[hi * width + wi + 2]);
                    Console.WriteLine(hi * width * 3 + wi);
                    Console.WriteLine(hi);
                    Console.WriteLine(wi);
                    Console.WriteLine();
                    //System.Drawing.Color color = SystemDrawing.Color.FromArgb(bytes[width * wi + hi], bytes[(width * wi + hi) + 1], bytes[(width * wi + hi) + 2]);
                    final.SetPixel(wi / 3, hi, color);
                }
            }


            actual.Source = ToSource(final);
        }
예제 #3
0
        /// <summary>
        /// Handler for when a fingerprint is captured.
        /// </summary>
        /// <param name="captureResult">contains info and data on the fingerprint capture</param>
        private void OnCaptured(CaptureResult captureResult)
        {
            try
            {
                // Check capture quality and throw an error if bad.
                if (!_sender.CheckCaptureResult(captureResult))
                {
                    return;
                }

                count++;

                DataResult <Fmd> resultConversion = FeatureExtraction.CreateFmdFromFid(captureResult.Data, Constants.Formats.Fmd.ANSI);

                if (count > 0)
                {
                    Fid.Fiv fiv = captureResult.Data.Views[0];
                    SendMessage(Action.SendBitmap, CreateBitmap(fiv.RawImage, fiv.Width, fiv.Height));
                }

                SendMessage(Action.SendMessage, "A Reading was captured.  \r\nCount:  " + (count));

                if (resultConversion.ResultCode != Constants.ResultCode.DP_SUCCESS)
                {
                    _sender.Reset = true;
                    throw new Exception(resultConversion.ResultCode.ToString());
                }

                preenrollmentFmds.Add(resultConversion.Data);

                if (count >= 4)
                {
                    DataResult <Fmd> resultEnrollment = DPUruNet.Enrollment.CreateEnrollmentFmd(Constants.Formats.Fmd.ANSI, preenrollmentFmds);

                    if (resultEnrollment.ResultCode == Constants.ResultCode.DP_SUCCESS)
                    {
                        SendMessage(Action.SendMessage, "An enrollment FMD was successfully created.");
                        SendMessage(Action.SendMessage, "Place Right Thumb on the device.");
                        preenrollmentFmds.Clear();
                        count = 0;

                        this.rightThumb = Fmd.SerializeXml(resultConversion.Data);

                        return;
                    }
                    else if (resultEnrollment.ResultCode == Constants.ResultCode.DP_ENROLLMENT_INVALID_SET)
                    {
                        SendMessage(Action.SendMessage, "Enrollment was unsuccessful.  Please try again.");
                        SendMessage(Action.SendMessage, "Place Right Thumb on the device.");
                        preenrollmentFmds.Clear();
                        count = 0;
                        return;
                    }
                }

                SendMessage(Action.SendMessage, "Now place the same finger on the device.");
            }
            catch (Exception ex)
            {
                // Send error message, then close form
                SendMessage(Action.SendMessage, "Error:  " + ex.Message);
            }
        }