2013-10-01 193 views
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); 
    }    
} 

回答

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"); 
+0

我用你的代碼,但在這裏的路徑是有必要提供圖像fil.for例如「D:\\ scanning image \\ lelo.jpg」的名稱我只是想給出的名稱這裏是掃描圖像的文件夾。我希望lelo.jpg在保存時由用戶輸入....你可以爲我分享完整的代碼。 –

相關問題