为了实现我所需要的,我执行以下操作:
我使用了 2 个库
1 - AForge.Imaging、AForge.Imaging.Formats和Delta.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;
}