2013-06-03 54 views
1

我的任務是創建一個文檔數字化程序,因爲該公司的樹枝接近可怕的。這不好。特別糟糕。經過一番研究,我開始了一個VB.NET WPF程序。我已經創建了登錄部分,並在要將文件發送到的服務器中創建文件夾,並將每個文件的位置保存在SQL表中。無論如何,我基本上需要三件讓我頭痛的事情!如何在掃描後顯示/保存多個(ADF)WIA圖像

1)如何使用WIA掃描多個頁面?這是我目前的,非常原始的掃描碼:

Dim CD As New WIA.CommonDialog 
    Dim txt As String 
    Dim picture As Image 

    Dim F As WIA.ImageFile = CD.ShowAcquireImage(WIA.WiaDeviceType.ScannerDeviceType) 
    txt = txt1.Text 
    F.SaveFile("\\serverlocation" + txt + "." + F.FileExtension) 

Txt基本上是用戶給出的名稱。問題是這段代碼只掃描一頁,我怎樣才能讓它在同一個文件/單獨的文件中保存多個? (以最好的爲準)。

  1. 在上一問題的同樣的精神,有沒有辦法將這些文件轉換爲JPEG/PNG(BMP需要的空間很多),或者如果用戶願意的,甚至將其轉換爲PDF文件?

  2. 如何在掃描後顯示掃描圖片?

我正在使用VB.NET和WPF(不是表格)。任何答覆將不勝感激:)。

編輯:最近的東西,我設法與http://forums.codeguru.com/showthread.php?439027-Windows-Image-Acquisition-%28WIA%29-Code多個ADF掃描。我將C#轉換爲VB,但代碼在編譯器中引發錯誤。

+0

如果你在做WPF,那麼你寧願做MVVM。這是獲得乾淨的代碼的最佳方式,並且執行更少的代碼以獲得更多結果。 –

+0

我會玩弄它。我已經習慣了這種模式的「範式」轉變。 –

+0

在WPF中,無論什麼時候需要N個'Items'(不管那是什麼東西),都可以使用'ItemsControl'。 –

回答

0
Private Function scanMe(ByVal myDPI As Integer, ByVal myHeight As Double, ByVal myWidth As Double, ByVal ShowSelectScanner As Boolean, ByVal ShowScanPreview As Boolean) As Byte() 
    Dim CD As New WIA.CommonDialog 
    Dim device As WIA.Device = CD.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, ShowSelectScanner, False) 
    Dim item As WIA.Item = device.Items(1) 
    Try 
     With item 
      .Properties("Horizontal Resolution").Value = myDPI 
      .Properties("Vertical Resolution").Value = myDPI 
      .Properties("Horizontal Extent").Value = myDPI * myWidth 
      .Properties("Vertical Extent").Value = myDPI * myHeight 
     End With 
     Dim F As WIA.ImageFile 

     If ShowScanPreview Then 
      F = CD.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent, WiaImageBias.MaximizeQuality, WIA.FormatID.wiaFormatBMP, False, True, False) 
     Else 
      F = CD.ShowTransfer(item, WIA.FormatID.wiaFormatPNG, False) 
     End If 

     Dim myBuffer As Byte() = F.FileData.BinaryData 
     Return myBuffer 
    Catch ex As Exception 

     MsgBox(ex.Message) 
     Return Nothing 
    End Try 
End Function 
+0

解釋一些關於你的答案 –