diff --git a/test/scannerlib/huagao/c#/WindowsFormsApp1/Form1.cs b/test/scannerlib/huagao/c#/WindowsFormsApp1/Form1.cs index 8b733879..0c3ffee3 100644 --- a/test/scannerlib/huagao/c#/WindowsFormsApp1/Form1.cs +++ b/test/scannerlib/huagao/c#/WindowsFormsApp1/Form1.cs @@ -32,6 +32,40 @@ namespace WindowsFormsApp1 saveParam.tiffJpegQuality = 80; saveParam.ocr = 0; HGScannerLib.HGLib_SaveImage(image, StringToUtf8("2.jpg"), ref saveParam); + + IntPtr imageData = HGScannerLib.HGLib_GetImageData(image); + + HGScannerLib.HGLibImageInfo imageInfo; + imageInfo.width = 0; + imageInfo.height = 0; + imageInfo.type = 0; + imageInfo.widthStep = 0; + imageInfo.origin = 0; + HGScannerLib.HGLib_GetImageInfo(image, ref imageInfo); + + Bitmap curBitmap = new Bitmap((int)imageInfo.width, (int)imageInfo.height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); + + Rectangle rect = new Rectangle(0, 0, (int)imageInfo.width, (int)imageInfo.height); + + System.Drawing.Imaging.BitmapData bmpData = curBitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb); + unsafe + { + byte* dest = (byte*)(bmpData.Scan0); + byte* src = (byte*)imageData; + for (int i = 0; i < (int)imageInfo.height; i++) + { + for (int j = 0; j < (int)imageInfo.width; j++) + { + dest[i * bmpData.Stride + j * 3 + 0] = src[i * imageInfo.widthStep + j * 3 + 2]; + dest[i * bmpData.Stride + j * 3 + 1] = src[i * imageInfo.widthStep + j * 3 + 1]; + dest[i * bmpData.Stride + j * 3 + 2] = src[i * imageInfo.widthStep + j * 3 + 0]; + } + } + } + curBitmap.UnlockBits(bmpData); + + curBitmap.Save("3.jpg"); + HGScannerLib.HGLib_ReleaseImage(image); } diff --git a/test/scannerlib/huagao/c#/WindowsFormsApp1/HGScannerLib.cs b/test/scannerlib/huagao/c#/WindowsFormsApp1/HGScannerLib.cs index 6341778b..c0678c89 100644 --- a/test/scannerlib/huagao/c#/WindowsFormsApp1/HGScannerLib.cs +++ b/test/scannerlib/huagao/c#/WindowsFormsApp1/HGScannerLib.cs @@ -18,6 +18,16 @@ namespace WindowsFormsApp1 public Int32 ocr; } + [StructLayout(LayoutKind.Sequential, Pack = 4)] + public struct HGLibImageInfo + { + public UInt32 width; + public UInt32 height; + public UInt32 type; + public UInt32 widthStep; + public UInt32 origin; + } + [StructLayout(LayoutKind.Sequential, Pack = 4)] public struct HGLibDeviceIntValueList { @@ -97,6 +107,12 @@ namespace WindowsFormsApp1 [DllImport("HGScannerLib.dll", EntryPoint = "HGLib_LoadImage")] public static extern UIntPtr HGLib_LoadImage(IntPtr filePath); + [DllImport("HGScannerLib.dll", EntryPoint = "HGLib_GetImageData")] + public static extern IntPtr HGLib_GetImageData(UIntPtr image); + + [DllImport("HGScannerLib.dll", EntryPoint = "HGLib_GetImageInfo")] + public static extern Int32 HGLib_GetImageInfo(UIntPtr image, ref HGLibImageInfo imageInfo); + [DllImport("HGScannerLib.dll", EntryPoint = "HGLib_SaveImage")] public static extern Int32 HGLib_SaveImage(UIntPtr image, IntPtr filePath, ref HGLibSaveImageParam saveParam);