Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
mobile_scanner
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
ryuta46
2023-04-12 07:27:21 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d9d4f69ebcc3175e9f8ea1484a6235cd0fb9a88c
d9d4f69e
1 parent
7acd36bc
imp: add resetZoomScale
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
1 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
ios/Classes/MobileScanner.swift
ios/Classes/SwiftMobileScannerPlugin.swift
lib/src/mobile_scanner_controller.dart
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
d9d4f69
...
...
@@ -289,4 +289,13 @@ class MobileScanner(
camera!!.cameraControl.setLinearZoom(scale.toFloat())
}
/**
* Reset the zoom rate of the camera.
*/
fun resetScale() {
if (camera == null) throw ZoomWhenStopped()
camera!!.cameraControl.setZoomRatio(1f)
}
}
...
...
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScannerHandler.kt
View file @
d9d4f69
...
...
@@ -120,6 +120,7 @@ class MobileScannerHandler(
"stop" -> stop(result)
"analyzeImage" -> analyzeImage(call, result)
"setScale" -> setScale(call, result)
"resetScale" -> resetScale(call, result)
"updateScanWindow" -> updateScanWindow(call)
else -> result.notImplemented()
}
...
...
@@ -234,6 +235,15 @@ class MobileScannerHandler(
}
}
private fun resetScale(call: MethodCall, result: MethodChannel.Result) {
try {
mobileScanner!!.resetScale()
result.success(null)
} catch (e: ZoomWhenStopped) {
result.error("MobileScanner", "Called setScale() while stopped!", null)
}
}
private fun updateScanWindow(call: MethodCall) {
mobileScanner!!.scanWindow = call.argument<List<Float>?>("rect")
}
...
...
ios/Classes/MobileScanner.swift
View file @
d9d4f69
...
...
@@ -52,6 +52,8 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
var
detectionSpeed
:
DetectionSpeed
=
DetectionSpeed
.
noDuplicates
var
standardZoomFactor
:
CGFloat
=
1
init
(
registry
:
FlutterTextureRegistry
?,
mobileScannerCallback
:
@escaping
MobileScannerCallback
,
torchModeChangeCallback
:
@escaping
TorchModeChangeCallback
,
zoomScaleChangeCallback
:
@escaping
ZoomScaleChangeCallback
)
{
self
.
registry
=
registry
self
.
mobileScannerCallback
=
mobileScannerCallback
...
...
@@ -140,6 +142,20 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
device
.
addObserver
(
self
,
forKeyPath
:
#
keyPath
(
AVCaptureDevice
.
torchMode
),
options
:
.
new
,
context
:
nil
)
device
.
addObserver
(
self
,
forKeyPath
:
#
keyPath
(
AVCaptureDevice
.
videoZoomFactor
),
options
:
.
new
,
context
:
nil
)
// Check the zoom factor at switching from ultra wide camera to wide camera.
standardZoomFactor
=
1
if
#available(iOS 13.0, *)
{
for
(
index
,
actualDevice
)
in
device
.
constituentDevices
.
enumerated
()
{
if
(
actualDevice
.
deviceType
!=
.
builtInUltraWideCamera
)
{
if
index
>
0
&&
index
<=
device
.
virtualDeviceSwitchOverVideoZoomFactors
.
count
{
standardZoomFactor
=
CGFloat
(
truncating
:
device
.
virtualDeviceSwitchOverVideoZoomFactors
[
index
-
1
])
}
break
}
}
}
do
{
try
device
.
lockForConfiguration
()
if
device
.
isFocusModeSupported
(
.
continuousAutoFocus
)
{
...
...
@@ -272,6 +288,22 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
/// Set the zoom factor of the camera
func
resetScale
()
throws
{
if
(
device
==
nil
)
{
throw
MobileScannerError
.
torchWhenStopped
}
do
{
try
device
.
lockForConfiguration
()
device
.
videoZoomFactor
=
standardZoomFactor
device
.
unlockForConfiguration
()
}
catch
{
throw
MobileScannerError
.
zoomError
(
error
)
}
}
/// Analyze a single image
func
analyzeImage
(
image
:
UIImage
,
position
:
AVCaptureDevice
.
Position
,
callback
:
@escaping
BarcodeScanningCallback
)
{
let
image
=
VisionImage
(
image
:
image
)
...
...
ios/Classes/SwiftMobileScannerPlugin.swift
View file @
d9d4f69
...
...
@@ -87,6 +87,8 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
analyzeImage
(
call
,
result
)
case
"setScale"
:
setScale
(
call
,
result
)
case
"resetScale"
:
resetScale
(
call
,
result
)
case
"updateScanWindow"
:
updateScanWindow
(
call
,
result
)
default
:
...
...
@@ -189,7 +191,28 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin {
}
result
(
nil
)
}
/// Reset the zoomScale
private
func
resetScale
(
_
call
:
FlutterMethodCall
,
_
result
:
@escaping
FlutterResult
)
{
do
{
try
mobileScanner
.
resetScale
()
}
catch
MobileScannerError
.
zoomWhenStopped
{
result
(
FlutterError
(
code
:
"MobileScanner"
,
message
:
"Called resetScale() while stopped!"
,
details
:
nil
))
}
catch
MobileScannerError
.
zoomError
(
let
error
)
{
result
(
FlutterError
(
code
:
"MobileScanner"
,
message
:
"Error while zooming."
,
details
:
error
))
}
catch
{
result
(
FlutterError
(
code
:
"MobileScanner"
,
message
:
"Error while zooming."
,
details
:
nil
))
}
result
(
nil
)
}
/// Toggles the torch
func
updateScanWindow
(
_
call
:
FlutterMethodCall
,
_
result
:
@escaping
FlutterResult
)
{
let
scanWindowData
:
Array
?
=
(
call
.
arguments
as?
[
String
:
Any
])?[
"rect"
]
as?
[
CGFloat
]
...
...
lib/src/mobile_scanner_controller.dart
View file @
d9d4f69
...
...
@@ -322,6 +322,12 @@ class MobileScannerController {
await
_methodChannel
.
invokeMethod
(
'setScale'
,
zoomScale
);
}
/// Reset the zoomScale of the camera to use standard scale 1x.
Future
<
void
>
resetZoomScale
()
async
{
await
_methodChannel
.
invokeMethod
(
'resetScale'
);
}
/// Disposes the MobileScannerController and closes all listeners.
///
/// If you call this, you cannot use this controller object anymore.
...
...
Please
register
or
login
to post a comment