如何使用WIA扫描双面(Duplex?)-C#

时间:2018-12-12 15:51:24

标签: c# scanning wia

我正在编写一种C#方法,该方法可以扫描很多文档,但是我需要从侧面扫描这些文档,即对于每张纸,请使用扫描仪的ADF扫描文档的正面和背面。但是我尝试了所有在互联网上找到的方法,但没有成功。我的代码如下:

        //user select the scanner
        int indexScanner = Convert.ToInt32(Console.ReadLine());

        // Connect to the first available scanner
        var device = deviceManager.DeviceInfos[indexScanner - 1].Connect();

        // Select the scanner
        var scannerItem = device.Items[1];

        int resolution = 150;
        int width_pixel = 1250;
        int height_pixel = 1700;
        int color_mode = 1;
        int adf_mode = 1;
        int pages_mode = 1;

        device.Properties["3096"].set_Value(pages_mode);
        //device.Properties["3088"].set_Value(adf_mode);
        scannerItem.Properties["3088"].set_Value(adf_mode);

        AdjustScannerSettings(scannerItem, resolution, 0, 0, width_pixel, height_pixel, 0, 0, color_mode);

        CommonDialogClass dlg = new CommonDialogClass();

            object scanResult = dlg.ShowTransfer(scannerItem, FormatID.wiaFormatJPEG, true);

            if (scanResult != null)
            {
                ImageFile image = (ImageFile)scanResult;

                string filename = "scan.jpeg";

                if (File.Exists(filename))
                    File.Delete(filename);

                image.SaveFile(filename);
            }

            scanResult = dlg.ShowTransfer(scannerItem, FormatID.wiaFormatJPEG, true);

            if (scanResult != null)
            {
                ImageFile image = (ImageFile)scanResult;

                string filename = "scan1.jpeg";

                if (File.Exists(filename))
                    File.Delete(filename);

                image.SaveFile(filename);
            }

0 个答案:

没有答案