[VB开发安卓]B4A类库 二维码,条形码,PDF417码识别和创建,界面仿微信早期版本扫一扫
B4A类库特点
1. 界面仿微信早期版本扫一扫
2.采用最新的谷歌ZXing 3.5.1版本核心识别库
3.双击扫码界面,可以打开闪光灯,辅助识别
4.集成,二维码,条形码,PDF417码的识别和创建
示例代码:
代码语言:javascript复制#Region Project Attributes
#ApplicationLabel: OhhZxing扫码示例
#VersionCode: 1
#VersionName: 一线编程
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private rp As RuntimePermissions ''权限控制
End Sub
Sub Globals
Private Button1 As Button
Private Button2 As Button
Private Button3 As Button
Private Button4 As Button
Private EditText1 As EditText
Private ImageView1 As ImageView
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout")
rp.CheckAndRequest(rp.PERMISSION_CAMERA) ''获取i相机权限
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
Log(Permission)
End Sub
''扫码(双击扫码框可以开启灯光)
''扫码目前支持市面上90%的条码,二维码,PDF417码
Private Sub Button1_Click
Dim ohhzxing As OhhZXing
ohhzxing.BeginScanCode("QrEvent")
Wait For QrEvent_result(atype As String,Values As String) ''扫码事件
EditText1.Text=Values ''扫码结果
End Sub
''创建二维码
Private Sub Button2_Click
If EditText1.Text="" Then
ToastMessageShow("内容不能为空",False)
Return
End If
Dim ohhzxing As OhhZXing
Dim barimg As Bitmap=ohhzxing.CreateQRcode(EditText1.Text,300,300)
If barimg.IsInitialized Then
FitCenterBitmap(ImageView1,barimg)
Else
ToastMessageShow("创建失败,含有不支持的字符串",False)
End If
End Sub
''创建PDF417二维码
Private Sub Button3_Click
If EditText1.Text="" Then
ToastMessageShow("内容不能为空",False)
Return
End If
Dim ohhzxing As OhhZXing
Dim barimg As Bitmap=ohhzxing.CreatePDF417code(EditText1.Text,300,300)
If barimg.IsInitialized Then
FitCenterBitmap(ImageView1,barimg)
Else
ToastMessageShow("创建失败,含有不支持的字符串",False)
End If
End Sub
''创建条形码
Private Sub Button4_Click
If EditText1.Text="" Then
ToastMessageShow("内容不能为空",False)
Return
End If
Dim ohhzxing As OhhZXing
Dim barimg As Bitmap=ohhzxing.CreateBarcode(EditText1.Text,300,150,"CODE_128")
If barimg.IsInitialized Then
FitCenterBitmap(ImageView1,barimg)
Else
ToastMessageShow("创建失败,含有不支持的字符串",False)
End If
End Sub
''填充图片
Public Sub FitCenterBitmap(Imv As ImageView, bmp As Bitmap)
Imv.Bitmap=Null
Dim cvs As Canvas
cvs.Initialize(Imv)
Dim rectDest As Rect
Dim delta As Int
If bmp.Width / bmp.Height > Imv.Width / Imv.Height Then
delta = (Imv.Height - bmp.Height / bmp.Width * Imv.Width) / 2
rectDest.Initialize(0, delta,Imv.Width, Imv.Height - delta)
Else
delta = (Imv.Width - bmp.Width / bmp.Height * Imv.Height) / 2
rectDest.Initialize(delta, 0, Imv.Width - delta, Imv.Height)
End If
cvs.DrawBitmap(bmp, Null, rectDest)
Imv.Invalidate
End Sub