扫描图像并将其保存在特定文件夹中

时间:2013-10-01 08:54:57

标签: c# winforms c#-4.0

我创建了一个Windows窗体应用程序来扫描任何图像。

完成扫描后,它会要求用户将其保存在任何文件夹中,但我希望将图像保存在特定文件夹中。

我使用的代码:

public class Scanner
{
    Device oDevice;
    Item oItem;
    CommonDialogClass dlg;

    public Scanner()
    {
        dlg = new CommonDialogClass();
        oDevice = dlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
    }

    public void Scann()
    {
        try
        {
            dlg.ShowAcquisitionWizard(oDevice);
        }
        catch (NullReferenceException ex)
        {
            MessageBox.Show(ex.Message);
        }

    }
}

private void button1_Click(object sender, EventArgs e)
{
   Scanner oScanner = new Scanner();
   oScanner.Scann();

   //Saving the image to the server directly
   button1.Text = "Image scanned";

   OpenFileDialog dlg = new OpenFileDialog();

   if (dlg.ShowDialog() == DialogResult.OK)
   {
       pictureBox1.Image = Image.FromFile(dlg.FileName);
   }            
}

2 个答案:

答案 0 :(得分:0)

使用CommonDialog.ShowTransfer method

示例:

Device scanner = dialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
Item scannnerItem = scanner.Items[1];
// TODO: Adjust scanner settings.

ImageFile scannedImage = (ImageFile)dialog.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatPNG, false);
scannedImage.SaveFile("path");

答案 1 :(得分:0)

相关问题