'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MCode
Friend Class Program
Shared Sub Main(ByVal args() As String)
Const IMAGE_FILE As String = MIL.M_IMAGE_PATH & "Code.mim"
Const STRING_LENGTH_MAX As Integer = 64
Const BARCODE_REGION_TOP_LEFT_X As Integer = 256
Const BARCODE_REGION_TOP_LEFT_Y As Integer = 80
Const BARCODE_REGION_SIZE_X As Integer = 290
Const BARCODE_REGION_SIZE_Y As Integer = 60
Const DATAMATRIX_REGION_TOP_LEFT_X As Integer = 8
Const DATAMATRIX_REGION_TOP_LEFT_Y As Integer = 312
Const DATAMATRIX_REGION_SIZE_X As Integer = 118
Const DATAMATRIX_REGION_SIZE_Y As Integer = 105
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilImage As MIL_ID = MIL.M_NULL
Dim MilOverlayImage As MIL_ID = MIL.M_NULL
Dim DataMatrixRegion As MIL_ID = MIL.M_NULL
Dim DataMatrixCode As MIL_ID = MIL.M_NULL
Dim BarCodeRegion As MIL_ID = MIL.M_NULL
Dim Barcode As MIL_ID = MIL.M_NULL
Dim CodeResults As MIL_ID = MIL.M_NULL
Dim BarcodeStatus As MIL_INT = MIL.M_NULL
Dim DataMatrixStatus As MIL_INT = MIL.M_NULL
Dim AnnotationColor As Double = MIL.M_COLOR_GREEN
Dim AnnotationBackColor As Double = MIL.M_COLOR_GRAY
Dim n As Integer = 0
Dim BarcodeString As New StringBuilder(STRING_LENGTH_MAX)
Dim DataMatrixString As New StringBuilder(STRING_LENGTH_MAX)
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MbufRestore(IMAGE_FILE, MilSystem, MilImage)
MIL.MdispSelect(MilDisplay, MilImage)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE)
MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, MilOverlayImage)
MIL.McodeAllocResult(MilSystem, MIL.M_DEFAULT, CodeResults)
Console.Write(Constants.vbLf + "1D and 2D CODE READING:" + Constants.vbLf)
Console.Write("-----------------------" + Constants.vbLf + Constants.vbLf)
Console.Write("This program will decode a linear Code 39 and a DataMatrix code." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MbufChild2d(MilImage, BARCODE_REGION_TOP_LEFT_X, BARCODE_REGION_TOP_LEFT_Y, BARCODE_REGION_SIZE_X, BARCODE_REGION_SIZE_Y, BarCodeRegion)
MIL.McodeAlloc(MilSystem, MIL.M_DEFAULT, MIL.M_DEFAULT, Barcode)
MIL.McodeModel(Barcode, MIL.M_ADD, MIL.M_CODE39, MIL.M_NULL, MIL.M_DEFAULT, CType(MIL.M_NULL, IntPtr))
MIL.McodeRead(Barcode, BarCodeRegion, CodeResults)
MIL.McodeGetResult(CodeResults, MIL.M_STATUS + MIL.M_TYPE_MIL_INT, BarcodeStatus)
If BarcodeStatus = MIL.M_STATUS_READ_OK Then
MIL.McodeGetResult(CodeResults, MIL.M_STRING, BarcodeString)
MIL.MgraColor(MIL.M_DEFAULT, AnnotationColor)
MIL.MgraBackColor(MIL.M_DEFAULT, AnnotationBackColor)
MIL.MgraText(MIL.M_DEFAULT, MilOverlayImage, BARCODE_REGION_TOP_LEFT_X + 10, BARCODE_REGION_TOP_LEFT_Y + 80, " 1D linear 39 bar code: ")
MIL.MgraText(MIL.M_DEFAULT, MilOverlayImage, BARCODE_REGION_TOP_LEFT_X + 200, BARCODE_REGION_TOP_LEFT_Y + 80, BarcodeString.ToString())
MIL.MgraRect(MIL.M_DEFAULT, MilOverlayImage, BARCODE_REGION_TOP_LEFT_X, BARCODE_REGION_TOP_LEFT_Y, BARCODE_REGION_TOP_LEFT_X + BARCODE_REGION_SIZE_X, BARCODE_REGION_TOP_LEFT_Y + BARCODE_REGION_SIZE_Y)
End If
MIL.McodeFree(Barcode)
MIL.MbufFree(BarCodeRegion)
MIL.MbufChild2d(MilImage, DATAMATRIX_REGION_TOP_LEFT_X, DATAMATRIX_REGION_TOP_LEFT_Y, DATAMATRIX_REGION_SIZE_X, DATAMATRIX_REGION_SIZE_Y, DataMatrixRegion)
MIL.McodeAlloc(MilSystem, MIL.M_DEFAULT, MIL.M_DEFAULT, DataMatrixCode)
MIL.McodeModel(DataMatrixCode, MIL.M_ADD, MIL.M_DATAMATRIX, MIL.M_NULL, MIL.M_DEFAULT, CType(MIL.M_NULL, IntPtr))
MIL.McodeControl(DataMatrixCode, MIL.M_FOREGROUND_VALUE, MIL.M_FOREGROUND_WHITE)
MIL.McodeRead(DataMatrixCode, DataMatrixRegion, CodeResults)
MIL.McodeGetResult(CodeResults, MIL.M_STATUS + MIL.M_TYPE_MIL_INT, DataMatrixStatus)
If DataMatrixStatus = MIL.M_STATUS_READ_OK Then
MIL.McodeGetResult(CodeResults, MIL.M_STRING, DataMatrixString)
MIL.MgraColor(MIL.M_DEFAULT, AnnotationColor)
MIL.MgraBackColor(MIL.M_DEFAULT, AnnotationBackColor)
For n = 0 To DataMatrixString.Length - 1
If (DataMatrixString(n) < "0"c) OrElse (DataMatrixString(n) > "Z"c) Then
DataMatrixString(n) = " "c
End If
Next n
MIL.MgraText(MIL.M_DEFAULT, MilOverlayImage, DATAMATRIX_REGION_TOP_LEFT_X, DATAMATRIX_REGION_TOP_LEFT_Y + 120, " 2D Data Matrix code: ")
MIL.MgraText(MIL.M_DEFAULT, MilOverlayImage, DATAMATRIX_REGION_TOP_LEFT_X + 200, DATAMATRIX_REGION_TOP_LEFT_Y + 120, DataMatrixString.ToString())
MIL.MgraRect(MIL.M_DEFAULT, MilOverlayImage, DATAMATRIX_REGION_TOP_LEFT_X, DATAMATRIX_REGION_TOP_LEFT_Y, DATAMATRIX_REGION_TOP_LEFT_X + DATAMATRIX_REGION_SIZE_X, DATAMATRIX_REGION_TOP_LEFT_Y + DATAMATRIX_REGION_SIZE_Y)
End If
MIL.McodeFree(DataMatrixCode)
MIL.MbufFree(DataMatrixRegion)
MIL.McodeFree(CodeResults)
If (DataMatrixStatus = MIL.M_STATUS_READ_OK) AndAlso (BarcodeStatus = MIL.M_STATUS_READ_OK) Then
Console.Write("Decoding was successful and the strings were written under each code." + Constants.vbLf)
Else
Console.Write("Decoding error found." + Constants.vbLf)
End If
Console.Write("Press <Enter> to end." + Constants.vbLf)
Console.ReadKey()
MIL.MbufFree(MilImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
End Class
End Namespace