ustva, etc.

This commit is contained in:
2025-04-29 17:18:24 +02:00
parent d3d2be1c08
commit bc24390692
7 changed files with 450 additions and 302 deletions

View File

@@ -18,6 +18,10 @@ Imports Dynamsoft.Core.Annotation
Imports Dynamsoft.TWAIN.Interface
Imports Dynamsoft.Core.Enums
Imports System.IO
Imports Dynamsoft.TWAIN.Enums
Imports Dynamsoft.DotTwain
Imports ClosedXML.Excel
Imports Dynamsoft.PDF.Enums
'Aktuell3
@@ -61,6 +65,23 @@ Public Class frmScan
End Sub
Public Enum TwainSupportedSizes As UShort
TWSS_NONE = 0
TWSS_A4 = 1
TWSS_JISB5 = 2
TWSS_USLETTER = 3
TWSS_USLEGAL = 4
TWSS_A5 = 5
TWSS_ISOB4 = 6
TWSS_ISOB6 = 7
TWSS_USLEDGER = 9
TWSS_USEXECUTIVE = 10
TWSS_A3 = 11
TWSS_B4 = 12
TWSS_B6 = 13
TWSS_BUSINESSCARD = 14
End Enum
Public Sub OnPostAllTransfers() Implements IAcquireCallback.OnPostAllTransfers
Me.Invoke(New CrossThreadOperationControl(AddressOf CallMe))
@@ -132,11 +153,11 @@ Public Class frmScan
dsViewer.Bind(m_ImageCore)
End Sub
<DllImport("kernel32.dll")> _
<DllImport("kernel32.dll")>
Private Shared Function GetSystemDirectory(<Out> lpBuffer As StringBuilder, uSize As UInteger) As UInteger
End Function
<DllImport("kernel32.dll")> _
<DllImport("kernel32.dll")>
Private Shared Function GetWindowsDirectory(<Out> lpBuffer As StringBuilder, uSize As UInteger) As UInteger
End Function
@@ -267,6 +288,10 @@ Public Class frmScan
m_TwainManager.SelectSourceByIndex(sSourceIndex)
'm_TwainManager.SetImageLayout(New Dynamsoft.Common.Margin(0.0, 0.0, width, height))
''vor Opensource
'Dim tmpFile = Path.GetTempFileName & ".pdf"
'tmpFile = "D:\Andreas\Dokumente\temptest<>.pdf"
@@ -314,6 +339,10 @@ Public Class frmScan
End If
m_TwainManager.Resolution = Integer.Parse(cboResolution.Text)
'Dim selectedPaper = CType(cboFormat.SelectedItem, KeyValuePair(Of String, Tuple(Of Double, Double)))
'Dim width = selectedPaper.Value.Item1
'Dim height = selectedPaper.Value.Item2
'm_TwainManager.sca()
@@ -400,6 +429,30 @@ Public Class frmScan
' hasWebcamSource = true;
hasTwainSource = True
Next
cboFormat.Items.Clear()
'Dim formats As New List(Of KeyValuePair(Of String, EnumPageSize)) From {
' New KeyValuePair(Of String, EnumPageSize)(" ", EnumPageSize.ImageSize),
' New KeyValuePair(Of String, EnumPageSize)("A4", EnumPageSize.A4),
' New KeyValuePair(Of String, EnumPageSize)("Legal", EnumPageSize.Legal),
' New KeyValuePair(Of String, EnumPageSize)("Letter", EnumPageSize.Letter)
' }
'cboFormat.DataSource = formats
Dim items = [Enum].GetValues(GetType(EnumPageSize)).Cast(Of EnumPageSize)().Select(Function(e) New KeyValuePair(Of String, EnumPageSize)(e.ToString(), e)).ToList()
With cboFormat
.DataSource = items
.DisplayMember = "Key"
.ValueMember = "Value"
End With
If hasTwainSource Then
cboSource.Enabled = True
' chkShowUI.Enabled = True
@@ -438,6 +491,12 @@ Public Class frmScan
Try
Select Case ART
Case "DirectScan"
If cboFormat.SelectedIndex >= 0 Then
Dim selectedPaper As EnumPageSize = CType(cboFormat.SelectedValue, EnumPageSize)
If cbxAltFormat.Checked Then m_PDFCreator.PageSize = selectedPaper
End If
Dim PDF_bytes As Byte() = m_PDFCreator.SaveAsBytes(TryCast(Me, ISave))
Me.fileName = addExtension(tbxSaveFileName.Text) ' DS.LAST_ID
Me.ReturnValue = PDF_bytes ' DS.LAST_ID
@@ -531,7 +590,10 @@ Public Class frmScan
SaveFileDialog.DefaultExt = "pdf"
If SaveFileDialog.ShowDialog() = DialogResult.OK Then
' Multi page PDF
If cboFormat.SelectedIndex >= 0 Then
Dim selectedPaper As EnumPageSize = CType(cboFormat.SelectedValue, EnumPageSize)
If cbxAltFormat.Checked Then m_PDFCreator.PageSize = selectedPaper
End If
m_PDFCreator.Save(TryCast(Me, ISave), SaveFileDialog.FileName)
End If
End If
@@ -575,12 +637,12 @@ Public Class frmScan
Dim iHeight As Integer = (tempAnnotation.EndPoint.X - tempAnnotation.StartPoint.X)
Select Case tempAnnotation.AnnotationType
'case AnnotationType.enumLine:
Case AnnotationType.enumEllipse, AnnotationType.enumRectangle, AnnotationType.enumText
Case Dynamsoft.Core.Enums.AnnotationType.enumEllipse, Dynamsoft.Core.Enums.AnnotationType.enumRectangle, Dynamsoft.Core.Enums.AnnotationType.enumText
tempAnnotation.StartPoint = New Point(x, y)
'tempAnnotation.Size = new Size(iWidth, iHeight);
tempAnnotation.EndPoint = New Point((tempAnnotation.StartPoint.X + iWidth), (tempAnnotation.StartPoint.Y + iHeight))
Exit Select
Case AnnotationType.enumLine
Case Dynamsoft.Core.Enums.AnnotationType.enumLine
Dim startPoint As Point = tempAnnotation.StartPoint
x = startPoint.Y
y = iImageWidth - startPoint.X
@@ -608,11 +670,11 @@ Public Class frmScan
Dim iHeight As Integer = tempAnnotation.Size.Width
Select Case tempAnnotation.AnnotationType
'case AnnotationType.enumLine:
Case AnnotationType.enumEllipse, AnnotationType.enumRectangle, AnnotationType.enumText
Case Dynamsoft.Core.Enums.AnnotationType.enumEllipse, Dynamsoft.Core.Enums.AnnotationType.enumRectangle, Dynamsoft.Core.Enums.AnnotationType.enumText
tempAnnotation.StartPoint = New Point(x, y)
tempAnnotation.EndPoint = New Point((tempAnnotation.StartPoint.X + iWidth), (tempAnnotation.StartPoint.Y + iHeight))
Exit Select
Case AnnotationType.enumLine
Case Dynamsoft.Core.Enums.AnnotationType.enumLine
Dim startPoint As Point = tempAnnotation.StartPoint
x = iImageHeight - startPoint.Y
y = startPoint.X
@@ -708,6 +770,10 @@ Public Class frmScan
Case "QuickScan"
Do
startScan()
If cboFormat.SelectedIndex >= 0 Then
Dim selectedPaper As EnumPageSize = CType(cboFormat.SelectedValue, EnumPageSize)
If cbxAltFormat.Checked Then m_PDFCreator.PageSize = selectedPaper
End If
Dim PDF_bytes As Byte() = m_PDFCreator.SaveAsBytes(TryCast(Me, ISave))
Me.fileName = addExtension(tbxSaveFileName.Text) ' DS.LAST_ID
Me.ReturnValue = PDF_bytes ' DS.LAST_ID
@@ -754,6 +820,10 @@ Public Class frmScan
Return True
'Throw New NotImplementedException()
End Function
Private Sub cbxAltFormat_CheckedChanged(sender As Object, e As EventArgs) Handles cbxAltFormat.CheckedChanged
cboFormat.Enabled = cbxAltFormat.Checked
End Sub
End Class