23-01-25, 07:34 PM
و عليكم السلام و رحمة الله وبركاته
يمكنك إنشاء برنامج بسيط في VB.NET لاستخدام الماسح الضوئي (scanner) لالتقاط الصور أو المستندات باستخدام مكتبة WIA (Windows Image Acquisition). إليك مثالًا أساسيًا:
المتطلبات:
تأكد من تثبيت تعريف الماسح الضوئي على جهازك.
قم بإضافة مرجع إلى مكتبة WIA في مشروعك:
اضغط على Project > Add Reference.
اذهب إلى علامة التبويب COM وابحث عن Microsoft Windows Image Acquisition Library وأضفها.
لم اقم بالتجربة لاني لا امتلك سكانر .
يمكنك إنشاء برنامج بسيط في VB.NET لاستخدام الماسح الضوئي (scanner) لالتقاط الصور أو المستندات باستخدام مكتبة WIA (Windows Image Acquisition). إليك مثالًا أساسيًا:
المتطلبات:
تأكد من تثبيت تعريف الماسح الضوئي على جهازك.
قم بإضافة مرجع إلى مكتبة WIA في مشروعك:
اضغط على Project > Add Reference.
اذهب إلى علامة التبويب COM وابحث عن Microsoft Windows Image Acquisition Library وأضفها.
PHP كود :
Imports System.IO
Imports System.Linq
Imports WIA
Imports System.Runtime.InteropServices
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
' التحقق من توفر الأجهزة
Dim deviceManager As New DeviceManager()
Dim scannerDevice = deviceManager.DeviceInfos.Cast(Of DeviceInfo)().
FirstOrDefault(Function(device) device.Type = WiaDeviceType.ScannerDeviceType)
If scannerDevice Is Nothing Then
MessageBox.Show(
"لا يوجد جهاز ماسح ضوئي متصل. الرجاء توصيل الجهاز والمحاولة مرة أخرى.",
"خطأ",
MessageBoxButtons.OK,
MessageBoxIcon.Warning)
Return
End If
' إنشاء واجهة الماسح الضوئي
Dim dialog As New WIA.CommonDialog()
Dim image As ImageFile = dialog.ShowAcquireImage(AlwaysSelectDevice:=True)
If image IsNot Nothing Then
' بناء المسار لحفظ الصورة
Dim folderPath As String = "C:\scanner"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Dim fileName As String = "My Files Scanned" & DateTime.Now.ToString("hhmmss") & ".jpg"
Dim fullPath As String = Path.Combine(folderPath, fileName)
' حفظ الصورة في المسار المحدد
image.SaveFile(fullPath)
' عرض الصورة في PictureBox
PictureBox1.Image = image.FromFile(fullPath)
End If
Catch ex As COMException
MessageBox.Show(
"حدث خطأ أثناء محاولة الوصول إلى جهاز الماسح الضوئي. الرجاء التحقق من الجهاز والمحاولة مرة أخرى.",
"خطأ",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show(
"حدث خطأ غير متوقع: " & ex.Message,
"خطأ",
MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
End Class
لم اقم بالتجربة لاني لا امتلك سكانر .
