public Sample ConvertRawBmpAsSample(Bitmap RawBmp, short VertDpi = 700, short HorDpi = 700) { VariantConverter VConverter; Enroller = new DPFP.Processing.Enrollment(); RawBmp = EncodeBitmap(RawBmp, VertDpi, HorDpi); try { // converts raw image to dpSample using DFC 2.0--------------------------------------- // encode the bmp variable using the bitmap Loader BitmapLoader BmpLoader = new BitmapLoader(RawBmp, (int)RawBmp.HorizontalResolution, (int)RawBmp.VerticalResolution); BmpLoader.ProcessBitmap(); // return the required result inputData = BmpLoader.RawData; inpRaw = BmpLoader.DPInputParam; // dispose the object BmpLoader.Dispose(); // start the conversion process VConverter = new VariantConverter(VariantConverter.OutputType.dp_sample, DataType.RawSample, inpRaw, inputData, false); MemoryStream DStream = new MemoryStream(VConverter.Convert()); DPsample = new DPFP.Sample(DStream); return(DPsample); } catch (Exception ex) { return(null /* TODO Change to default(_) if this is not a reference type */); } }
public VariantConverter(OutputType Output, DigitalPersona.Standards.DataType _dataType, DigitalPersona.Standards.InputParameterForRaw _inpRaw, byte[] _inputData, bool _WriteOutputToFile = false) { try { cbOutputType = Output; dataType = _dataType; inpRaw = _inpRaw; inputData = _inputData; WriteOutputToFile = _WriteOutputToFile; } catch (Exception ex) { throw ex; } }
public DPFP.Template ConvertRawBmpAsTemplate(Bitmap RawBmp, DataPurpose ProcessPurpose = DataPurpose.Enrollment, short VertDpi = 700, short HorDpi = 700) { VariantConverter VConverter; Enroller = new DPFP.Processing.Enrollment(); RawBmp = EncodeBitmap(RawBmp, VertDpi, HorDpi); try { // converts raw image to dpSample using DFC 2.0--------------------------------------- // encode the bmp variable using the bitmap Loader BitmapLoader BmpLoader = new BitmapLoader(RawBmp, (int)RawBmp.HorizontalResolution, (int)RawBmp.VerticalResolution); BmpLoader.ProcessBitmap(); // return the required result inputData = BmpLoader.RawData; inpRaw = BmpLoader.DPInputParam; // dispose the object BmpLoader.Dispose(); // start the conversion process VConverter = new VariantConverter(VariantConverter.OutputType.dp_sample, DataType.RawSample, inpRaw, inputData, false); MemoryStream DStream = new MemoryStream(VConverter.Convert()); DPsample = new DPFP.Sample(DStream); // DPsample = DirectCast(VConverter.Convert(), DPFP.Sample) // converts dpSample to DPFeatures using the OTW''''''''''''''''''''''''''''''''''''''' DPFeatures = ExtractFeatures(DPsample, ProcessPurpose); // convert DPfeatures to ISO FMD using the DFC 2.0''''''''''''''''''''''''''''''''''''''' byte[] SerializedFeatures = null; DPFeatures.Serialize(ref SerializedFeatures); // serialized features into the array of bytes ISOFMD = DigitalPersona.Standards.Converter.Convert(SerializedFeatures, DigitalPersona.Standards.DataType.DPFeatureSet, DataType.ISOFeatureSet); // convert ISO FMD to DPTemplate using DFC 2.0''''''''''''''''''''''''''''''''''''''' byte[] DPTemplateData = DigitalPersona.Standards.Converter.Convert(ISOFMD, DigitalPersona.Standards.DataType.ISOTemplate, DataType.DPTemplate); // deserialize data to Template DPTemplate = new DPFP.Template(); DPTemplate.DeSerialize(DPTemplateData); // required for database purpose // ============================================================================ DStream.Close(); return(DPTemplate); } catch (Exception ex) { return(null /* TODO Change to default(_) if this is not a reference type */); } }
public void ProcessBitmap() { int width = 0; int height = 0; int dpiX = 0; int dpiY = 0; int bpp = 0; try { dpiX = Convert.ToInt32(tbXdpi); dpiY = Convert.ToInt32(tbYdpi); width = bmp.Width; height = bmp.Height; System.Drawing.Imaging.BitmapData bmpData; Rectangle rect = new Rectangle(0, 0, width, height); switch (bmp.PixelFormat) { case System.Drawing.Imaging.PixelFormat.Format8bppIndexed: { m_rawData = new byte[width * height - 1 + 1]; // what about padding? bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat); Marshal.Copy(bmpData.Scan0, m_rawData, 0, width * height); bmp.UnlockBits(bmpData); inpRaw = new DigitalPersona.Standards.InputParameterForRaw(width, height, dpiX, dpiY, 8); this.DialogResult = System.Windows.Forms.DialogResult.OK; break; } case System.Drawing.Imaging.PixelFormat.Format24bppRgb: { m_rawData = new byte[width * height - 1 + 1]; bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat); for (int y = 0; y <= height - 1; y++) { for (int x = 0; x <= width - 1; x++) { // Calculate greyscale based on average RGB intensity int i = x * 3 + y * bmpData.Stride; int Dividend = Marshal.ReadByte(bmpData.Scan0, i); int Dividend2 = Marshal.ReadByte(bmpData.Scan0, i + 1); int Dividend3 = Marshal.ReadByte(bmpData.Scan0, i + 2); int avg_val = (Dividend + Dividend2 + Dividend3) / 3; // Convert to byte and save gray scale data m_rawData[x + y * width] = System.Convert.ToByte(avg_val); } } // ---------------------------- bmp.UnlockBits(bmpData); inpRaw = new DigitalPersona.Standards.InputParameterForRaw(width, height, dpiX, dpiY, 8); break; } case System.Drawing.Imaging.PixelFormat.Format32bppArgb: case System.Drawing.Imaging.PixelFormat.Format32bppRgb: { m_rawData = new byte[width * height - 1 + 1]; bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat); for (int y = 0; y <= height - 1; y++) { for (int x = 0; x <= width - 1; x++) { // Calculate greyscale based on average RGB intensity int i = x * 4 + y * bmpData.Stride; int Dividend = Marshal.ReadByte(bmpData.Scan0, i); int Dividend2 = Marshal.ReadByte(bmpData.Scan0, i + 1); int Dividend3 = Marshal.ReadByte(bmpData.Scan0, i + 2); int avg_val = (Dividend + Dividend2 + Dividend3) / 3; m_rawData[x + y * width] = System.Convert.ToByte(avg_val); } } // ---------------------------- bmp.UnlockBits(bmpData); inpRaw = new DigitalPersona.Standards.InputParameterForRaw(width, height, dpiX, dpiY, 8); break; } default: { MessageBox.Show("Bitmap format not supported. Please convert to either 8bpp indexed or 24 bpp non-indexed"); this.DialogResult = System.Windows.Forms.DialogResult.Cancel; break; } } this.Close(); } catch (Exception ex) { try { logger.WriteLog(ex); } catch (Exception exx) { } MessageBox.Show(ex.Message); return; } }