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
casvanluijtelaar
2022-06-15 15:27:28 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e31a4756b61ec4c3712f0e2b475971438f58e562
e31a4756
1 parent
7bc3af1d
bugfixes
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
2 deletions
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
example/lib/barcode_scanner_window.dart
lib/src/mobile_scanner.dart
lib/src/mobile_scanner_controller.dart
android/src/main/kotlin/dev/steenbakker/mobile_scanner/MobileScanner.kt
View file @
e31a475
...
...
@@ -143,12 +143,20 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:
val imageWidth = inputImage.getWidth();
val imageHeight = inputImage.getHeight();
println(inputImage.getWidth())
println(inputImage.getHeight())
println(barcodeBoundingBox)
val left = (scanWindow[0] * imageWidth).roundToInt()
val top = (scanWindow[1] * imageHeight).roundToInt()
val right = (scanWindow[2] * imageWidth).roundToInt()
val bottom = (scanWindow[3] * imageHeight).roundToInt()
val scaledScanWindow = Rect(left, top, right, bottom)
println(scaledScanWindow)
println("-------------------------")
return scaledScanWindow.contains(barcodeBoundingBox)
}
...
...
@@ -227,6 +235,8 @@ class MobileScanner(private val activity: Activity, private val textureRegistry:
val analysisSize = analysis.resolutionInfo?.resolution ?: Size(0, 0)
val previewSize = preview!!.resolutionInfo?.resolution ?: Size(0, 0)
Log.i("LOG", "Analyzer: $analysisSize")
Log.i("LOG", "Preview: $previewSize")
...
...
example/lib/barcode_scanner_window.dart
View file @
e31a475
...
...
@@ -18,6 +18,12 @@ class _BarcodeScannerWithScanWindowState
void
initState
()
{
super
.
initState
();
controller
=
MobileScannerController
();
restart
();
}
Future
<
void
>
restart
()
async
{
await
controller
.
stop
();
await
controller
.
start
();
}
@override
...
...
lib/src/mobile_scanner.dart
View file @
e31a475
...
...
@@ -89,6 +89,7 @@ class _MobileScannerState extends State<MobileScanner>
Size
textureSize
,
Size
widgetSize
,
)
{
/// map the texture size to get its new size after fitted to screen
final
fittedSizes
=
applyBoxFit
(
fit
,
textureSize
,
widgetSize
);
final
fittedTextureSize
=
fittedSizes
.
destination
;
...
...
@@ -103,6 +104,7 @@ class _MobileScannerState extends State<MobileScanner>
/// create a new scan window and with only the area of the rect intersecting the texture window
final
scanWindowInTexture
=
scanWindow
.
intersect
(
textureWindow
);
/// update the scanWindow left and top to be relative to the texture not the widget
final
newLeft
=
scanWindowInTexture
.
left
-
textureWindow
.
left
;
final
newTop
=
scanWindowInTexture
.
top
-
textureWindow
.
top
;
...
...
@@ -112,17 +114,26 @@ class _MobileScannerState extends State<MobileScanner>
/// new scanWindow that is adapted to the boxfit and relative to the texture
final
windowInTexture
=
Rect
.
fromLTWH
(
newLeft
,
newTop
,
newWidth
,
newHeight
);
print
(
windowInTexture
);
/// get the scanWindow as a percentage of the texture
final
percentageLeft
=
windowInTexture
.
left
/
fittedTextureSize
.
width
;
final
percentageTop
=
windowInTexture
.
top
/
fittedTextureSize
.
height
;
final
percentageRight
=
windowInTexture
.
right
/
fittedTextureSize
.
width
;
final
percentagebottom
=
windowInTexture
.
bottom
/
fittedTextureSize
.
height
;
print
(
Rect
.
fromLTRB
(
percentageLeft
,
percentageTop
,
percentageRight
,
percentagebottom
,
));
/// this rectangle can be send to native code and used to cut out a rectangle of the scan image
return
Rect
.
fromLTRB
(
percentageLeft
,
percentageRight
,
percentageTop
,
percentageRight
,
percentagebottom
,
);
}
...
...
lib/src/mobile_scanner_controller.dart
View file @
e31a475
...
...
@@ -294,7 +294,7 @@ class MobileScannerController {
/// updates the native scanwindow
Future
<
void
>
updateScanWindow
(
Rect
window
)
async
{
final
data
=
[
window
.
left
,
window
.
right
,
window
.
top
,
window
.
bottom
];
final
data
=
[
window
.
left
,
window
.
top
,
window
.
right
,
window
.
bottom
];
await
methodChannel
.
invokeMethod
(
'updateScanWindow'
,
{
'rect'
:
data
});
}
}
...
...
Please
register
or
login
to post a comment