|
在楼主的基础上稍加修改而编成的“万能解码”,
其原理是循环利用编码库内的所有(22套)编码格式对指定的图像文件进行解码,直到解出来为止,
原理并不复杂,不敢藏私,希望大家能用得上。
- '读取图像文件进行万能解码
- Sub Decode_All_From_File()
- Dim Reader As IBarcodeReader, Res As Result, FullFileName$,Arr(), Brr(), i%
- With Application.FileDialog(msoFileDialogFilePicker) '"文件选取器" 对话框
- .Title = "请选择一个图像文件" '标题
- .InitialFileName = "C:" '默认路径(和默认文件名)
- .Filters.Clear '清除当前文件过滤器
- .Filters.Add "Picture Files", "*.bmp;*.gif;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.wmf" '增加文件过滤器
- If .Show = 0 Then Exit Sub '显示对话框。按OK返回-1,按Cancel返回0
- FullFileName = .SelectedItems(1)
- End With
- Arr = Array(1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 61918)
- Brr = Array("AZTEC", "CODABAR", "CODE_39", "CODE_93", "CODE_128", "DATA_MATRIX", "EAN_8", "EAN_13", "ITF", "MAXICODE", "PDF_417", "QR_CODE", "RSS_14", "RSS_EXPANDED", "UPC_A", "UPC_E", "UPC_EAN_EXTENSION", "MSI", "PLESSEY", "IMB", "PHARMA_CODE", "All_1D")
- Set Reader = New BarcodeReader
- For i = LBound(Arr) To UBound(Arr)
- Reader.Options.PossibleFormats.Clear '清除原编码格式
- Reader.Options.PossibleFormats.Add Arr(i) '添加编码格式
- Set Res = Reader.DecodeImageFile(FullFileName)
- If Len(Res.Text) Then Exit For
- Next i
- If i > UBound(Arr) Then
- MsgBox "图像文件 " & FullFileName & " 解码失败!"
- Else
- MsgBox "文件名:" & FullFileName & vbLf & vbLf & "编码类型:" & Brr(i) & vbLf & vbLf & "解码结果:" & Res.Text
- End If
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|