如何在C#应用程序中通过扫描仪扫描图像时使用进度条

时间:2015-07-19 05:34:07

标签: c# wia

在我的C#应用​​程序中,我通过WIA使用扫描仪,这里我的要求是扫描仪应扫描1到50张图像的一组图像,我在我的应用程序中添加了一个文本框,用于输入要扫描的图像数量。

我的应用程序必须从文本框中取出数字,扫描程序应扫描多次。我的问题是这个扫描部分工作得很好,而扫描进度条只显示扫描第一张图像,扫描剩余图像时没有显示。

这是我正在使用的代码:

namespace Scnr2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
        InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SaveFileDialog FBD = new SaveFileDialog();

            if (FBD.ShowDialog() == DialogResult.OK)
            {
                int n = Convert.ToInt32(textBox1.Text);
                for (int i = 0; i < n; i++)
                {
                    ScannerService sr = new ScannerService();
                    ImageFile image = sr.Scan();


                     image.SaveFile(FBD.FileName + ".jpg");

                }
            }
        }
    }

    public class ScannerService
    {
        public ImageFile Scan()
        {
            ImageFile image;

            WIA.CommonDialog dialog = new WIA.CommonDialog();
            DeviceManager dm = new DeviceManagerClass();

            Device scannerDevice = dialog.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, false, false);

            Item scannerItem;

            if (scannerDevice == null)
                MessageBox.Show("No");
            if (scannerDevice != null)
            {
                scannerItem = scannerDevice.Items[1];

                image = dialog.ShowAcquireImage(
                    WIA.WiaDeviceType.ScannerDeviceType,
                    WIA.WiaImageIntent.ColorIntent,
                    WIA.WiaImageBias.MaximizeQuality,
                    WIA.FormatID.wiaFormatJPEG,
                    false,
                    true,
                    false);

                return image;


            }
            return null;
        }

    }
}

0 个答案:

没有答案
相关问题