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
Julian Steenbakker
2022-11-09 16:40:52 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5af3a81e6ca285ba3b88b4581b861f55f2e792bc
5af3a81e
1 parent
a7369089
bug: fixed rotation on return image on iOS
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
46 deletions
example/lib/barcode_scanner_returning_image.dart
ios/Classes/MobileScanner.swift
ios/Classes/MobileScannerUtilities.swift
lib/src/mobile_scanner.dart
lib/src/mobile_scanner_controller.dart
example/lib/barcode_scanner_returning_image.dart
View file @
5af3a81
...
...
@@ -85,38 +85,33 @@ class _BarcodeScannerReturningImageState
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
spaceEvenly
,
children:
[
ColoredBox
(
color:
arguments
!=
null
&&
!
arguments
!.
hasTorch
?
Colors
.
red
:
Colors
.
white
,
child:
IconButton
(
// color: ,
icon:
ValueListenableBuilder
(
valueListenable:
controller
.
torchState
,
builder:
(
context
,
state
,
child
)
{
if
(
state
==
null
)
{
IconButton
(
color:
Colors
.
white
,
icon:
ValueListenableBuilder
(
valueListenable:
controller
.
torchState
,
builder:
(
context
,
state
,
child
)
{
if
(
state
==
null
)
{
return
const
Icon
(
Icons
.
flash_off
,
color:
Colors
.
grey
,
);
}
switch
(
state
as
TorchState
)
{
case
TorchState
.
off
:
return
const
Icon
(
Icons
.
flash_off
,
color:
Colors
.
grey
,
);
}
switch
(
state
as
TorchState
)
{
case
TorchState
.
off
:
return
const
Icon
(
Icons
.
flash_off
,
color:
Colors
.
grey
,
);
case
TorchState
.
on
:
return
const
Icon
(
Icons
.
flash_on
,
color:
Colors
.
yellow
,
);
}
},
),
iconSize:
32.0
,
onPressed:
()
=>
controller
.
toggleTorch
(),
case
TorchState
.
on
:
return
const
Icon
(
Icons
.
flash_on
,
color:
Colors
.
yellow
,
);
}
},
),
iconSize:
32.0
,
onPressed:
()
=>
controller
.
toggleTorch
(),
),
IconButton
(
color:
Colors
.
white
,
...
...
ios/Classes/MobileScanner.swift
View file @
5af3a81
...
...
@@ -230,16 +230,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega
}
}
/// Convert image buffer to jpeg
private
func
ciImageToJpeg
(
ciImage
:
CIImage
)
->
Data
{
// let ciImage = CIImage(cvPixelBuffer: latestBuffer)
let
context
:
CIContext
=
CIContext
.
init
(
options
:
nil
)
let
cgImage
:
CGImage
=
context
.
createCGImage
(
ciImage
,
from
:
ciImage
.
extent
)
!
let
uiImage
:
UIImage
=
UIImage
(
cgImage
:
cgImage
,
scale
:
1
,
orientation
:
UIImage
.
Orientation
.
up
)
return
uiImage
.
jpegData
(
compressionQuality
:
0.8
)
!
;
}
// /// Convert image buffer to jpeg
// private func ciImageToJpeg(ciImage: CIImage) -> Data {
//
// // let ciImage = CIImage(cvPixelBuffer: latestBuffer)
// let context:CIContext = CIContext.init(options: nil)
// let cgImage:CGImage = context.createCGImage(ciImage, from: ciImage.extent)!
// let uiImage:UIImage = UIImage(cgImage: cgImage, scale: 1, orientation: UIImage.Orientation.up)
//
// return uiImage.jpegData(compressionQuality: 0.8)!;
// }
/// Rotates images accordingly
func
imageOrientation
(
...
...
ios/Classes/MobileScannerUtilities.swift
View file @
5af3a81
...
...
@@ -21,7 +21,7 @@ extension CVBuffer {
var
image
:
UIImage
{
let
ciImage
=
CIImage
(
cvPixelBuffer
:
self
)
let
cgImage
=
CIContext
()
.
createCGImage
(
ciImage
,
from
:
ciImage
.
extent
)
return
UIImage
(
cgImage
:
cgImage
!
)
return
UIImage
(
cgImage
:
cgImage
!
,
scale
:
1.0
,
orientation
:
UIImage
.
Orientation
.
left
)
}
var
image1
:
UIImage
{
...
...
lib/src/mobile_scanner.dart
View file @
5af3a81
...
...
@@ -52,24 +52,30 @@ class _MobileScannerState extends State<MobileScanner>
if
(!
controller
.
isStarting
)
controller
.
start
();
}
AppLifecycleState
?
_lastStat
e
;
bool
resumeFromBackground
=
fals
e
;
@override
void
didChangeAppLifecycleState
(
AppLifecycleState
state
)
{
// App state changed before it is initialized.
if
(
controller
.
isStarting
)
{
return
;
}
switch
(
state
)
{
case
AppLifecycleState
.
resumed
:
if
(!
controller
.
isStarting
&&
widget
.
autoResume
&&
_lastState
!=
AppLifecycleState
.
inactive
)
controller
.
start
();
resumeFromBackground
=
false
;
controller
.
start
();
break
;
case
AppLifecycleState
.
paused
:
case
AppLifecycleState
.
detached
:
controller
.
stop
();
resumeFromBackground
=
true
;
break
;
case
AppLifecycleState
.
inactive
:
if
(!
resumeFromBackground
)
controller
.
stop
();
break
;
default
:
break
;
}
_lastState
=
state
;
}
@override
...
...
lib/src/mobile_scanner_controller.dart
View file @
5af3a81
...
...
@@ -202,7 +202,11 @@ class MobileScannerController {
/// Stops the camera, but does not dispose this controller.
Future
<
void
>
stop
()
async
{
await
_methodChannel
.
invokeMethod
(
'stop'
);
try
{
await
_methodChannel
.
invokeMethod
(
'stop'
);
}
catch
(
e
)
{
debugPrint
(
'
$e
'
);
}
}
/// Switches the torch on or off.
...
...
Please
register
or
login
to post a comment