Update 20211218
This commit is contained in:
244
_B4A/SteriScan/Camera.b4a
Normal file
244
_B4A/SteriScan/Camera.b4a
Normal file
@@ -0,0 +1,244 @@
|
||||
Build1=Default,anywheresoftware.b4a.samples.camera
|
||||
File1=1.bal
|
||||
FileGroup1=Default Group
|
||||
Group=Default Group
|
||||
Library1=camera
|
||||
Library10=stringfunctions
|
||||
Library2=core
|
||||
Library3=javaobject
|
||||
Library4=json
|
||||
Library5=okhttputils2
|
||||
Library6=phone
|
||||
Library7=reflection
|
||||
Library8=runtimepermissions
|
||||
Library9=xui
|
||||
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: http://www.basic4ppc.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>~\n~<supports-screens android:largeScreens="true" ~\n~ android:normalScreens="true" ~\n~ android:smallScreens="true" ~\n~ android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~'End of default text.~\n~'************ Google Play Services Base ************~\n~AddApplicationText(~\n~ <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"~\n~ android:theme="@android:style/Theme.Translucent.NoTitleBar"~\n~ android:exported="false"/>~\n~ <meta-data~\n~ android:name="com.google.android.gms.version"~\n~ android:value="@integer/google_play_services_version" />~\n~)~\n~'************ Google Play Services Base (end) ************~\n~AddApplicationText(<meta-data~\n~ android:name="com.google.android.gms.vision.DEPENDENCIES"~\n~ android:value="barcode,,face" />~\n~)~\n~
|
||||
Module1=CameraExClass
|
||||
Module2=Starter
|
||||
NumberOfFiles=1
|
||||
NumberOfLibraries=10
|
||||
NumberOfModules=2
|
||||
Version=11
|
||||
@EndOfDesignText@
|
||||
#Region Module Attributes
|
||||
#FullScreen: False
|
||||
#IncludeTitle: False
|
||||
#ApplicationLabel: SteriScan
|
||||
#VersionCode: 1
|
||||
#VersionName:
|
||||
#SupportedOrientations: unspecified
|
||||
#CanInstallToExternalStorage: False
|
||||
#End Region
|
||||
#AdditionalJar: com.google.android.gms:play-services-vision
|
||||
#BridgeLogger: true
|
||||
'Activity module
|
||||
Sub Process_Globals
|
||||
Private frontCamera As Boolean = False
|
||||
Private detector As JavaObject
|
||||
Private SearchForBarcodes As Boolean
|
||||
Private LastPreview As Long
|
||||
Private IntervalBetweenPreviewsMs As Int = 100
|
||||
End Sub
|
||||
|
||||
Sub Globals
|
||||
Private Panel1 As Panel
|
||||
Private camEx As CameraExClass
|
||||
Private pnlDrawing As Panel
|
||||
Private cvs As B4XCanvas
|
||||
End Sub
|
||||
|
||||
Sub Activity_Create(FirstTime As Boolean)
|
||||
Activity.LoadLayout("1")
|
||||
If FirstTime Then
|
||||
CreateDetector (Array("CODE_128", "CODE_93"))
|
||||
End If
|
||||
cvs.Initialize(pnlDrawing)
|
||||
End Sub
|
||||
|
||||
Private Sub CreateDetector (Codes As List)
|
||||
Dim ctxt As JavaObject
|
||||
ctxt.InitializeContext
|
||||
Dim builder As JavaObject
|
||||
builder.InitializeNewInstance("com/google/android/gms/vision/barcode/BarcodeDetector.Builder".Replace("/", "."), Array(ctxt))
|
||||
Dim barcodeClass As String = "com/google/android/gms/vision/barcode/Barcode".Replace("/", ".")
|
||||
Dim barcodeStatic As JavaObject
|
||||
barcodeStatic.InitializeStatic(barcodeClass)
|
||||
Dim format As Int
|
||||
For Each formatName As String In Codes
|
||||
format = Bit.Or(format, barcodeStatic.GetField(formatName))
|
||||
Next
|
||||
builder.RunMethod("setBarcodeFormats", Array(format))
|
||||
detector = builder.RunMethod("build", Null)
|
||||
Dim operational As Boolean = detector.RunMethod("isOperational", Null)
|
||||
Log("Is detector operational: " & operational)
|
||||
SearchForBarcodes = operational
|
||||
|
||||
End Sub
|
||||
|
||||
Sub Camera1_Preview (data() As Byte)
|
||||
If SearchForBarcodes Then
|
||||
If DateTime.Now > LastPreview + IntervalBetweenPreviewsMs Then
|
||||
'Dim n As Long = DateTime.Now
|
||||
cvs.ClearRect(cvs.TargetRect)
|
||||
Dim frameBuilder As JavaObject
|
||||
Dim bb As JavaObject
|
||||
bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
|
||||
frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
|
||||
Dim cs As CameraSize = camEx.GetPreviewSize
|
||||
frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height, 842094169))
|
||||
Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
|
||||
Dim SparseArray As JavaObject = detector.RunMethod("detect", Array(frame))
|
||||
LastPreview = DateTime.Now
|
||||
Dim Matches As Int = SparseArray.RunMethod("size", Null)
|
||||
For i = 0 To Matches - 1
|
||||
Dim barcode As JavaObject = SparseArray.RunMethod("valueAt", Array(i))
|
||||
Dim raw As String = barcode.GetField("rawValue")
|
||||
Log(raw)
|
||||
ToastMessageShow("Found: " & raw, True)
|
||||
Dim points() As Object = barcode.GetField("cornerPoints")
|
||||
Dim tl As JavaObject = points(0)
|
||||
' Dim tr As JavaObject = points(1)
|
||||
Dim br As JavaObject = points(2)
|
||||
' Dim bl As JavaObject = points(3)
|
||||
Dim r As B4XRect
|
||||
|
||||
Dim size As CameraSize = camEx.GetPreviewSize
|
||||
Dim xscale, yscale As Float
|
||||
If camEx.PreviewOrientation Mod 180 = 0 Then
|
||||
xscale = Panel1.Width / size.Width
|
||||
yscale = Panel1.Height / size.Height
|
||||
r.Initialize(tl.GetField("x"), tl.GetField("y"), br.GetField("x"), br.GetField("y"))
|
||||
Else
|
||||
xscale = Panel1.Width / size.Height
|
||||
yscale = Panel1.Height / size.Width
|
||||
r.Initialize(br.GetField("y"), br.GetField("x"), tl.GetField("y"),tl.GetField("x"))
|
||||
End If
|
||||
|
||||
Select camEx.PreviewOrientation
|
||||
Case 180
|
||||
r.Initialize(size.Width - r.Right, size.Height - r.Bottom, size.Width - r.Left, size.Height - r.Top)
|
||||
Case 90
|
||||
r.Initialize(size.Height - r.Right, r.Top, size.Height - r.Left, r.Bottom)
|
||||
End Select
|
||||
r.Left = r.Left * xscale
|
||||
r.Right = r.Right * xscale
|
||||
r.Top = r.Top * yscale
|
||||
r.Bottom = r.Bottom * yscale
|
||||
cvs.DrawRect(r, Colors.Red, False, 5dip)
|
||||
Next
|
||||
If Matches = 0 Then
|
||||
cvs.ClearRect(cvs.TargetRect)
|
||||
End If
|
||||
cvs.Invalidate
|
||||
|
||||
'Log(DateTime.Now - n)
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Activity_Resume
|
||||
InitializeCamera
|
||||
End Sub
|
||||
|
||||
Private Sub InitializeCamera
|
||||
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_CAMERA)
|
||||
Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||
If Result Then
|
||||
camEx.Initialize(Panel1, frontCamera, Me, "Camera1")
|
||||
frontCamera = camEx.Front
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Activity_Pause (UserClosed As Boolean)
|
||||
If camEx.IsInitialized Then
|
||||
camEx.Release
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Sub Camera1_Ready (Success As Boolean)
|
||||
If Success Then
|
||||
camEx.SetJpegQuality(90)
|
||||
camEx.SetContinuousAutoFocus
|
||||
camEx.CommitParameters
|
||||
camEx.StartPreview
|
||||
|
||||
Else
|
||||
ToastMessageShow("Cannot open camera.", True)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
'Sub btnTakePicture_Click
|
||||
' camEx.TakePicture
|
||||
'End Sub
|
||||
'
|
||||
'Sub btnFocus_Click
|
||||
' camEx.FocusAndTakePicture
|
||||
'End Sub
|
||||
|
||||
Sub Camera1_PictureTaken (Data() As Byte)
|
||||
' Dim filename As String = "1.jpg"
|
||||
' Dim dir As String = File.DirRootExternal
|
||||
'
|
||||
' camEx.SavePictureToFile(Data, dir, filename)
|
||||
' camEx.StartPreview 'restart preview
|
||||
'
|
||||
' 'send a broadcast intent to the media scanner to force it to scan the saved file.
|
||||
' Dim Phone As Phone
|
||||
' Dim i As Intent
|
||||
' i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
|
||||
' "file://" & File.Combine(dir, filename))
|
||||
' Phone.SendBroadcastIntent(i)
|
||||
' ToastMessageShow("Picture saved." & CRLF & "File size: " & File.Size(dir, filename), True)
|
||||
End Sub
|
||||
|
||||
Sub ChangeCamera_Click
|
||||
camEx.Release
|
||||
frontCamera = Not(frontCamera)
|
||||
InitializeCamera
|
||||
End Sub
|
||||
|
||||
Sub btnEffect_Click
|
||||
Dim effects As List = camEx.GetSupportedColorEffects
|
||||
If effects.IsInitialized = False Then
|
||||
ToastMessageShow("Effects not supported.", False)
|
||||
Return
|
||||
End If
|
||||
Dim effect As String = effects.Get((effects.IndexOf(camEx.GetColorEffect) + 1) Mod effects.Size)
|
||||
camEx.SetColorEffect(effect)
|
||||
ToastMessageShow(effect, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
|
||||
Sub btnFlash_Click
|
||||
Dim f() As Float = camEx.GetFocusDistances
|
||||
Log(f(0) & ", " & f(1) & ", " & f(2))
|
||||
Dim flashModes As List = camEx.GetSupportedFlashModes
|
||||
If flashModes.IsInitialized = False Then
|
||||
ToastMessageShow("Flash not supported.", False)
|
||||
Return
|
||||
End If
|
||||
Dim flash As String = flashModes.Get((flashModes.IndexOf(camEx.GetFlashMode) + 1) Mod flashModes.Size)
|
||||
camEx.SetFlashMode(flash)
|
||||
ToastMessageShow(flash, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
Sub btnPictureSize_Click
|
||||
Dim pictureSizes() As CameraSize = camEx.GetSupportedPicturesSizes
|
||||
Dim current As CameraSize = camEx.GetPictureSize
|
||||
For i = 0 To pictureSizes.Length - 1
|
||||
If pictureSizes(i).Width = current.Width And pictureSizes(i).Height = current.Height Then Exit
|
||||
Next
|
||||
Dim ps As CameraSize = pictureSizes((i + 1) Mod pictureSizes.Length)
|
||||
camEx.SetPictureSize(ps.Width, ps.Height)
|
||||
ToastMessageShow(ps.Width & "x" & ps.Height, False)
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
|
||||
|
||||
Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
|
||||
If UserChanged = False Or camEx.IsZoomSupported = False Then Return
|
||||
camEx.Zoom = Value / 100 * camEx.GetMaxZoom
|
||||
camEx.CommitParameters
|
||||
End Sub
|
||||
12
_B4A/SteriScan/Camera.b4a.meta
Normal file
12
_B4A/SteriScan/Camera.b4a.meta
Normal file
@@ -0,0 +1,12 @@
|
||||
ModuleBookmarks0=
|
||||
ModuleBookmarks1=
|
||||
ModuleBookmarks2=
|
||||
ModuleBreakpoints0=
|
||||
ModuleBreakpoints1=
|
||||
ModuleBreakpoints2=
|
||||
ModuleClosedNodes0=
|
||||
ModuleClosedNodes1=
|
||||
ModuleClosedNodes2=
|
||||
NavigationStack=Main,Camera1_Ready,116,6,Main,Process_Globals,17,0,CameraExClass,FaceDetection_Event,380,0,CameraExClass,Class_Globals,16,4,CameraExClass,SetDisplayOrientation,80,2,Main,Globals,25,0,Main,btnEffect_Click,167,0,Main,SeekBar1_ValueChanged,209,0,Main,Camera1_Preview,98,6,Main,CreateDetector,35,0
|
||||
SelectedBuild=0
|
||||
VisibleModules=1,2
|
||||
404
_B4A/SteriScan/CameraExClass.bas
Normal file
404
_B4A/SteriScan/CameraExClass.bas
Normal file
@@ -0,0 +1,404 @@
|
||||
B4A=true
|
||||
Group=Default Group
|
||||
ModulesStructureVersion=1
|
||||
Type=Class
|
||||
Version=7.28
|
||||
@EndOfDesignText@
|
||||
'Class module
|
||||
'version 1.30
|
||||
'See this page for the list of constants:
|
||||
'http://developer.android.com/intl/fr/reference/android/hardware/Camera.Parameters.html
|
||||
'Note that you should use the constant values instead of the names.
|
||||
Sub Class_Globals
|
||||
Private nativeCam As Object
|
||||
Private cam As Camera
|
||||
Private r As Reflector
|
||||
Private target As Object
|
||||
Private event As String
|
||||
Public Front As Boolean
|
||||
Type CameraInfoAndId (CameraInfo As Object, Id As Int)
|
||||
Type CameraSize (Width As Int, Height As Int)
|
||||
Private parameters As Object
|
||||
|
||||
Public PreviewOrientation As Int
|
||||
End Sub
|
||||
|
||||
Public Sub Initialize (Panel1 As Panel, FrontCamera As Boolean, TargetModule As Object, EventName As String)
|
||||
target = TargetModule
|
||||
event = EventName
|
||||
Front = FrontCamera
|
||||
Dim id As Int
|
||||
id = FindCamera(Front).id
|
||||
If id = -1 Then
|
||||
Front = Not(Front) 'try different camera
|
||||
id = FindCamera(Front).id
|
||||
If id = -1 Then
|
||||
ToastMessageShow("No camera found.", True)
|
||||
Return
|
||||
End If
|
||||
End If
|
||||
cam.Initialize2(Panel1, "camera", id)
|
||||
End Sub
|
||||
|
||||
Private Sub FindCamera (frontCamera As Boolean) As CameraInfoAndId
|
||||
Dim ci As CameraInfoAndId
|
||||
Dim cameraInfo As Object
|
||||
Dim cameraValue As Int
|
||||
Log("findCamera")
|
||||
If frontCamera Then cameraValue = 1 Else cameraValue = 0
|
||||
cameraInfo = r.CreateObject("android.hardware.Camera$CameraInfo")
|
||||
Dim numberOfCameras As Int = r.RunStaticMethod("android.hardware.Camera", "getNumberOfCameras", Null, Null)
|
||||
Log(r.target)
|
||||
Log(numberOfCameras)
|
||||
For i = 0 To numberOfCameras - 1
|
||||
r.RunStaticMethod("android.hardware.Camera", "getCameraInfo", Array As Object(i, cameraInfo), _
|
||||
Array As String("java.lang.int", "android.hardware.Camera$CameraInfo"))
|
||||
r.target = cameraInfo
|
||||
Log("facing: " & r.GetField("facing") & ", " & cameraValue)
|
||||
If r.GetField("facing") = cameraValue Then
|
||||
ci.cameraInfo = r.target
|
||||
ci.Id = i
|
||||
Return ci
|
||||
End If
|
||||
Next
|
||||
ci.id = -1
|
||||
Return ci
|
||||
End Sub
|
||||
|
||||
Private Sub SetDisplayOrientation
|
||||
r.target = r.GetActivity
|
||||
r.target = r.RunMethod("getWindowManager")
|
||||
r.target = r.RunMethod("getDefaultDisplay")
|
||||
r.target = r.RunMethod("getRotation")
|
||||
Dim result, degrees As Int = r.target * 90
|
||||
Dim ci As CameraInfoAndId = FindCamera(Front)
|
||||
r.target = ci.CameraInfo
|
||||
Dim orientation As Int = r.GetField("orientation")
|
||||
If Front Then
|
||||
PreviewOrientation = (orientation + degrees) Mod 360
|
||||
result = PreviewOrientation
|
||||
PreviewOrientation = (360 - PreviewOrientation) Mod 360
|
||||
Else
|
||||
PreviewOrientation = (orientation - degrees + 360) Mod 360
|
||||
result = PreviewOrientation
|
||||
Log("Preview Orientation: " & PreviewOrientation)
|
||||
End If
|
||||
r.target = nativeCam
|
||||
r.RunMethod2("setDisplayOrientation", PreviewOrientation, "java.lang.int")
|
||||
r.target = parameters
|
||||
r.RunMethod2("setRotation", result, "java.lang.int")
|
||||
CommitParameters
|
||||
End Sub
|
||||
|
||||
Private Sub Camera_Ready (Success As Boolean)
|
||||
If Success Then
|
||||
r.target = cam
|
||||
nativeCam = r.GetField("camera")
|
||||
r.target = nativeCam
|
||||
parameters = r.RunMethod("getParameters")
|
||||
SetDisplayOrientation
|
||||
Else
|
||||
Log("success = false, " & LastException)
|
||||
End If
|
||||
CallSub2(target, event & "_ready", Success)
|
||||
End Sub
|
||||
'Uncomment this sub if you need to handle the Preview event
|
||||
Sub Camera_Preview (Data() As Byte)
|
||||
If SubExists(target, event & "_preview") Then
|
||||
CallSub2(target, event & "_preview", Data)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub TakePicture
|
||||
cam.TakePicture
|
||||
End Sub
|
||||
|
||||
Private Sub Camera_PictureTaken (Data() As Byte)
|
||||
CallSub2(target, event & "_PictureTaken", Data)
|
||||
End Sub
|
||||
|
||||
Public Sub StartPreview
|
||||
cam.StartPreview
|
||||
End Sub
|
||||
|
||||
Public Sub StopPreview
|
||||
cam.StopPreview
|
||||
End Sub
|
||||
|
||||
Public Sub Release
|
||||
cam.Release
|
||||
End Sub
|
||||
|
||||
'Saves the data received from PictureTaken event
|
||||
Public Sub SavePictureToFile(Data() As Byte, Dir As String, FileName As String)
|
||||
Dim out As OutputStream = File.OpenOutput(Dir, FileName, False)
|
||||
out.WriteBytes(Data, 0, Data.Length)
|
||||
out.Close
|
||||
End Sub
|
||||
|
||||
Public Sub SetParameter(Key As String, Value As String)
|
||||
r.target = parameters
|
||||
r.RunMethod3("set", Key, "java.lang.String", Value, "java.lang.String")
|
||||
End Sub
|
||||
|
||||
Public Sub GetParameter(Key As String) As String
|
||||
r.target = parameters
|
||||
Return r.RunMethod2("get", Key, "java.lang.String")
|
||||
End Sub
|
||||
|
||||
Public Sub CommitParameters
|
||||
'Try
|
||||
r.target = nativeCam
|
||||
r.RunMethod4("setParameters", Array As Object(parameters), Array As String("android.hardware.Camera$Parameters"))
|
||||
'Catch
|
||||
' ToastMessageShow("Error setting parameters.", True)
|
||||
' Log(LastException)
|
||||
' End Try
|
||||
End Sub
|
||||
|
||||
Public Sub GetColorEffect As String
|
||||
Return GetParameter("effect")
|
||||
End Sub
|
||||
|
||||
Public Sub SetColorEffect(Effect As String)
|
||||
SetParameter("effect", Effect)
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedPreviewSizes As CameraSize()
|
||||
r.target = parameters
|
||||
Dim list1 As List = r.RunMethod("getSupportedPreviewSizes")
|
||||
Dim cs(list1.Size) As CameraSize
|
||||
For i = 0 To list1.Size - 1
|
||||
r.target = list1.get(i)
|
||||
cs(i).Width = r.GetField("width")
|
||||
cs(i).Height = r.GetField("height")
|
||||
Next
|
||||
Return cs
|
||||
End Sub
|
||||
|
||||
Public Sub SetPreviewSize(Width As Int, Height As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod3("setPreviewSize", Width, "java.lang.int", Height, "java.lang.int")
|
||||
End Sub
|
||||
Public Sub GetSupportedPicturesSizes As CameraSize()
|
||||
r.target = parameters
|
||||
Dim list1 As List = r.RunMethod("getSupportedPictureSizes")
|
||||
Dim cs(list1.Size) As CameraSize
|
||||
For i = 0 To list1.Size - 1
|
||||
r.target = list1.get(i)
|
||||
cs(i).Width = r.GetField("width")
|
||||
cs(i).Height = r.GetField("height")
|
||||
Next
|
||||
Return cs
|
||||
End Sub
|
||||
|
||||
Public Sub SetPictureSize(Width As Int, Height As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod3("setPictureSize", Width, "java.lang.int", Height, "java.lang.int")
|
||||
End Sub
|
||||
|
||||
Public Sub SetJpegQuality(Quality As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod2("setJpegQuality", Quality, "java.lang.int")
|
||||
End Sub
|
||||
|
||||
Public Sub SetFlashMode(Mode As String)
|
||||
r.target = parameters
|
||||
r.RunMethod2("setFlashMode", Mode, "java.lang.String")
|
||||
End Sub
|
||||
|
||||
Public Sub GetFlashMode As String
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getFlashMode")
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedFlashModes As List
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getSupportedFlashModes")
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedColorEffects As List
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getSupportedColorEffects")
|
||||
End Sub
|
||||
|
||||
'Returns a list with the supported preview fps. Each item in the list is an array of two ints (minimum value and maximum value).
|
||||
Public Sub GetSupportedPreviewFpsRange As List
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getSupportedPreviewFpsRange")
|
||||
End Sub
|
||||
'Returns the current preview fps range.
|
||||
'Range is a two elements array. The minimum value and maximum value will be stored in this array.
|
||||
Public Sub GetPreviewFpsRange(Range() As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod4("getPreviewFpsRange", Array As Object(Range), Array As String("[I"))
|
||||
End Sub
|
||||
|
||||
Public Sub SetPreviewFpsRange(MinValue As Int, MaxValue As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod4("setPreviewFpsRange", Array As Object(MinValue, MaxValue), _
|
||||
Array As String("java.lang.int", "java.lang.int"))
|
||||
End Sub
|
||||
|
||||
Public Sub GetPreviewSize As CameraSize
|
||||
r.target = parameters
|
||||
r.target = r.RunMethod("getPreviewSize")
|
||||
Dim cs As CameraSize
|
||||
cs.Width = r.GetField("width")
|
||||
cs.Height = r.GetField("height")
|
||||
Return cs
|
||||
End Sub
|
||||
|
||||
Public Sub GetPictureSize As CameraSize
|
||||
r.target = parameters
|
||||
r.target = r.RunMethod("getPictureSize")
|
||||
Dim cs As CameraSize
|
||||
cs.Width = r.GetField("width")
|
||||
cs.Height = r.GetField("height")
|
||||
Return cs
|
||||
End Sub
|
||||
|
||||
'Converts a preview image formatted in YUV format to JPEG.
|
||||
'Note that you should not save every preview image as it will slow down the whole process.
|
||||
Public Sub PreviewImageToJpeg(data() As Byte, quality As Int) As Byte()
|
||||
Dim size, previewFormat As Object
|
||||
r.target = parameters
|
||||
size = r.RunMethod("getPreviewSize")
|
||||
previewFormat = r.RunMethod("getPreviewFormat")
|
||||
r.target = size
|
||||
Dim width = r.GetField("width"), height = r.GetField("height") As Int
|
||||
Dim yuvImage As Object = r.CreateObject2("android.graphics.YuvImage", _
|
||||
Array As Object(data, previewFormat, width, height, Null), _
|
||||
Array As String("[B", "java.lang.int", "java.lang.int", "java.lang.int", "[I"))
|
||||
r.target = yuvImage
|
||||
Dim rect1 As Rect
|
||||
rect1.Initialize(0, 0, r.RunMethod("getWidth"), r.RunMethod("getHeight"))
|
||||
Dim out As OutputStream
|
||||
out.InitializeToBytesArray(100)
|
||||
r.RunMethod4("compressToJpeg", Array As Object(rect1, quality, out), _
|
||||
Array As String("android.graphics.Rect", "java.lang.int", "java.io.OutputStream"))
|
||||
|
||||
Return out.ToBytesArray
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedFocusModes As List
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getSupportedFocusModes")
|
||||
End Sub
|
||||
|
||||
Public Sub SetContinuousAutoFocus
|
||||
Dim modes As List = GetSupportedFocusModes
|
||||
If modes.IndexOf("continuous-picture") > -1 Then
|
||||
SetFocusMode("continuous-picture")
|
||||
Else If modes.IndexOf("continuous-video") > -1 Then
|
||||
SetFocusMode("continuous-video")
|
||||
Else
|
||||
Log("Continuous focus mode is not available")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub SetFocusMode(Mode As String)
|
||||
r.target = parameters
|
||||
r.RunMethod2("setFocusMode", Mode, "java.lang.String")
|
||||
End Sub
|
||||
|
||||
Public Sub GetFocusDistances As Float()
|
||||
Dim F(3) As Float
|
||||
r.target = parameters
|
||||
r.RunMethod4("getFocusDistances", Array As Object(F), Array As String("[F"))
|
||||
Return F
|
||||
End Sub
|
||||
|
||||
Public Sub GetSupportedPictureFormats As List
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getSupportedPictureFormats")
|
||||
End Sub
|
||||
'This method should only be called if you need to immediately release the camera.
|
||||
'For example if you need to start another application that depends on the camera.
|
||||
Public Sub CloseNow
|
||||
cam.Release
|
||||
r.target = cam
|
||||
r.RunMethod2("releaseCameras", True, "java.lang.boolean")
|
||||
End Sub
|
||||
'Calls AutoFocus and then takes the picture if focus was successfull.
|
||||
Public Sub FocusAndTakePicture
|
||||
cam.AutoFocus
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub Camera_FocusDone (Success As Boolean)
|
||||
If Success Then
|
||||
Sleep(100)
|
||||
TakePicture
|
||||
Else
|
||||
Log("AutoFocus error.")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub IsZoomSupported As Boolean
|
||||
r.target = parameters
|
||||
Return r.RunMethod("isZoomSupported")
|
||||
End Sub
|
||||
|
||||
Public Sub GetMaxZoom As Int
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getMaxZoom")
|
||||
End Sub
|
||||
|
||||
Public Sub getZoom() As Int
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getZoom")
|
||||
End Sub
|
||||
|
||||
Public Sub setZoom(ZoomValue As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod2("setZoom", ZoomValue, "java.lang.int")
|
||||
End Sub
|
||||
|
||||
Public Sub getExposureCompensation As Int
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getExposureCompensation")
|
||||
End Sub
|
||||
|
||||
Public Sub setExposureCompensation(v As Int)
|
||||
r.target = parameters
|
||||
r.RunMethod2("setExposureCompensation", v, "java.lang.int")
|
||||
End Sub
|
||||
|
||||
Public Sub getMinExposureCompensation As Int
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getMinExposureCompensation")
|
||||
End Sub
|
||||
|
||||
Public Sub getMaxExposureCompensation As Int
|
||||
r.target = parameters
|
||||
Return r.RunMethod("getMaxExposureCompensation")
|
||||
End Sub
|
||||
|
||||
Public Sub SetFaceDetectionListener
|
||||
Dim jo As JavaObject = nativeCam
|
||||
Dim e As Object = jo.CreateEvent("android.hardware.Camera.FaceDetectionListener", "FaceDetection", Null)
|
||||
jo.RunMethod("setFaceDetectionListener", Array(e))
|
||||
End Sub
|
||||
|
||||
Private Sub FaceDetection_Event (MethodName As String, Args() As Object) As Object
|
||||
Dim faces() As Object = Args(0)
|
||||
For Each f As Object In faces
|
||||
Dim jo As JavaObject = f
|
||||
Dim faceRect As Rect = jo.GetField("rect")
|
||||
Next
|
||||
Return Null
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
Public Sub StartFaceDetection
|
||||
Dim jo As JavaObject = nativeCam
|
||||
jo.RunMethod("startFaceDetection", Null)
|
||||
End Sub
|
||||
|
||||
Public Sub StopFaceDetection
|
||||
Dim jo As JavaObject = nativeCam
|
||||
jo.RunMethod("stopFaceDetection", Null)
|
||||
End Sub
|
||||
|
||||
BIN
_B4A/SteriScan/Files/1.bal
Normal file
BIN
_B4A/SteriScan/Files/1.bal
Normal file
Binary file not shown.
52
_B4A/SteriScan/Objects/AndroidManifest.xml
Normal file
52
_B4A/SteriScan/Objects/AndroidManifest.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="anywheresoftware.b4a.samples.camera"
|
||||
android:versionCode="1"
|
||||
android:versionName=""
|
||||
android:installLocation="internalOnly">
|
||||
|
||||
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="26"/>
|
||||
<supports-screens android:largeScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:smallScreens="true"
|
||||
android:anyDensity="true"/>
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="SteriScan">
|
||||
|
||||
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:exported="false"/>
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.vision.DEPENDENCIES"
|
||||
android:value="barcode,face" />
|
||||
<activity
|
||||
android:windowSoftInputMode="stateHidden"
|
||||
android:launchMode="singleTop"
|
||||
android:name=".main"
|
||||
android:label="SteriScan"
|
||||
android:screenOrientation="unspecified">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
<service android:name=".starter">
|
||||
</service>
|
||||
<receiver android:name=".starter$starter_BR">
|
||||
</receiver>
|
||||
<service android:name=".httputils2service">
|
||||
</service>
|
||||
<receiver android:name=".httputils2service$httputils2service_BR">
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
BIN
_B4A/SteriScan/Objects/Camera_RAPID_DEBUG.apk
Normal file
BIN
_B4A/SteriScan/Objects/Camera_RAPID_DEBUG.apk
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$anim.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$anim.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$attr.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$attr.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$color.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$color.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$dimen.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$dimen.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$id.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$id.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$integer.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$integer.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$layout.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$layout.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$string.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$string.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$style.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R$style.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/core/R.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/drawerlayout/R.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/drawerlayout/R.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/fragment/R$id.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/fragment/R$id.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/fragment/R.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/fragment/R.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$anim.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$anim.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$attr.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$attr.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$color.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$color.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$dimen.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$dimen.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$id.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$id.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$layout.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$layout.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$string.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$string.class
Normal file
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$style.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R$style.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R.class
Normal file
BIN
_B4A/SteriScan/Objects/bin/classes/androidx/media/R.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user