0

我正在使用 Digital Persona 指纹设备,需要将图像捕获为WSQ格式而不是Bmp格式
使用C# DigitalPersona One Touch for Windows SDK

示例代码

private DPFP.Capture.SampleConversion SampleConversion;
private Bitmap Image;
public async void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
        {

            var imgName = string.Format("fingerprint{0}.bmp", DateTime.Now.Ticks);
            SampleConversion.ConvertToPicture(Sample, ref Image);
            Image.Save(imgName, System.Drawing.Imaging.ImageFormat.Bmp);
        }

我在 C# 中找到了转换bmpwsq wsqEncodeDecode的库,但结果wsq不正确,是否有任何解决方案可以直接从 sdk
以格式返回捕获的图像?wsq

4

1 回答 1

1

为了实现我所需要的,我执行以下操作:

我使用了 2 个库

1 - AForge.ImagingAForge.Imaging.FormatsDelta.Wsq DLL

            private Bitmap Image;

        public async void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
           {
            SampleConversion.ConvertToPicture(Sample, ref Image);
            Image.RotateFlip(RotateFlipType.Rotate180FlipNone);
            Image = resizeImage(364, 400, Image);
            var img8bppx = Grayscale.CommonAlgorithms.BT709.Apply(Image);

            var rawImageData = Conversions.GdiImageToImageInfo(img8bppx);
            WsqEncoder encoder = new WsqEncoder();
            var result = encoder.Encode(rawImageData);
            }

并且是调整大小的方法

public Bitmap resizeImage(int newWidth, int newHeight, Image imgPhoto)
        {
            int sourceWidth = imgPhoto.Width;
            int sourceHeight = imgPhoto.Height;

            //Consider vertical pics
            if (sourceWidth < sourceHeight)
            {
                int buff = newWidth;

                newWidth = newHeight;
                newHeight = buff;
            }

            int sourceX = 0, sourceY = 0, destX = 0, destY = 0;
            float nPercent = 0, nPercentW = 0, nPercentH = 0;

            nPercentW = ((float)newWidth / (float)sourceWidth);
            nPercentH = ((float)newHeight / (float)sourceHeight);
            if (nPercentH < nPercentW)
            {
                nPercent = nPercentH;
                destX = System.Convert.ToInt16((newWidth -
                          (sourceWidth * nPercent)) / 2);
            }
            else
            {
                nPercent = nPercentW;
                destY = System.Convert.ToInt16((newHeight -
                          (sourceHeight * nPercent)) / 2);
            }

            int destWidth = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);


            Bitmap bmPhoto = new Bitmap(newWidth, newHeight,
                          PixelFormat.Format24bppRgb);

            bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
                         imgPhoto.VerticalResolution);

            Graphics grPhoto = Graphics.FromImage(bmPhoto);
            grPhoto.Clear(Color.Black);
            grPhoto.InterpolationMode =
                System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

            grPhoto.DrawImage(imgPhoto,
                new Rectangle(destX, destY, destWidth, destHeight),
                new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                GraphicsUnit.Pixel);

            grPhoto.Dispose();
            imgPhoto.Dispose();
            return bmPhoto;
        }
于 2020-03-20T12:52:54.927 回答