Julian Steenbakker

bug: fixed rotation on return image on iOS

... ... @@ -85,12 +85,8 @@ class _BarcodeScannerReturningImageState
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ColoredBox(
color: arguments != null && !arguments!.hasTorch
? Colors.red
: Colors.white,
child: IconButton(
// color: ,
IconButton(
color: Colors.white,
icon: ValueListenableBuilder(
valueListenable: controller.torchState,
builder: (context, state, child) {
... ... @@ -117,7 +113,6 @@ class _BarcodeScannerReturningImageState
iconSize: 32.0,
onPressed: () => controller.toggleTorch(),
),
),
IconButton(
color: Colors.white,
icon: isStarted
... ...
... ... @@ -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(
... ...
... ... @@ -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 {
... ...
... ... @@ -52,24 +52,30 @@ class _MobileScannerState extends State<MobileScanner>
if (!controller.isStarting) controller.start();
}
AppLifecycleState? _lastState;
bool resumeFromBackground = false;
@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
... ...
... ... @@ -202,7 +202,11 @@ class MobileScannerController {
/// Stops the camera, but does not dispose this controller.
Future<void> stop() async {
try {
await _methodChannel.invokeMethod('stop');
} catch (e) {
debugPrint('$e');
}
}
/// Switches the torch on or off.
... ...