我用dart&java开发,当我从cameraStream发送图像数据到native(java)时,该应用程序将停止运行,实际上它是黑屏并在那里暂停。日志显示“与设备的连接断开”。发生在相机ResolutionPreset为中高时。质量低,它可以工作,但不能使用,因为图像太小且质量低。 最后感谢您的帮助。 :)
代码:
@override
void initState() {
// TODO: implement initState
super.initState();
if(widget.cameras == null || widget.cameras.length < 1){
print("No Cameara is found");
}else{
onCameraSelected(widget.cameras[0]);
}
}
void onCameraSelected(CameraDescription description)async{
controller = CameraController(description, ResolutionPreset.medium);
controller.addListener((){
if(mounted)setState(() {
});
if(controller.value.hasError){
print("camera error :${controller.value.errorDescription}");
}
});
controller.initialize().then((_){
if(!mounted){
return;
}
setState(() {
});
controller.startImageStream((CameraImage image){
if(! isDetecting){
isDetecting = true;
CameraImage imageStream = image;
Future.delayed(Duration(seconds: 3)).then((_){
FlutterPlugin.jump(
bytesList: imageStream.planes.map((plane){
return plane.bytes;
}).toList()
,width: imageStream.width,
height: imageStream.height
,numResults: 2,
ratio:( imageStream.width / imageStream.height));
});
}
});
});
日志信息:
E/flutter ( 6983): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: CameraException(No camera is streaming images, stopImageStream was called when no camera is streaming images.)
E/flutter ( 6983): #0 CameraController.stopImageStream (package:camera/camera.dart:397:7)
E/flutter ( 6983):
E/flutter ( 6983): #1 _MyHomePageState.onCameraSelected.. (package:flutter_decode_qr_demo_1/main.dart:127:24)
E/flutter ( 6983): #2 _rootRun (dart:async/zone.dart:1120:38)
E/flutter ( 6983): #3 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 6983): #4 _FutureListener.handleWhenComplete (dart:async/future_impl.dart:150:18)
E/flutter ( 6983): #5 Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:609:39)
E/flutter ( 6983): #6 Future._propagateToListeners (dart:async/future_impl.dart:665:37)
E/flutter ( 6983): #7 Future._complete (dart:async/future_impl.dart:473:7)
E/flutter ( 6983): #8 new Future.delayed. (dart:async/future.dart:313:16)
E/flutter ( 6983): #9 _rootRun (dart:async/zone.dart:1120:38)
E/flutter ( 6983): #10 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 6983): #11 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter ( 6983): #12 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:963:23)
E/flutter ( 6983): #13 _rootRun (dart:async/zone.dart:1124:13)
E/flutter ( 6983): #14 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter ( 6983): #15 _CustomZone.bindCallback. (dart:async/zone.dart:947:23)
E/flutter ( 6983): #16 Timer._createTimer. (dart:async/runtime/libtimer_patch.dart:21:15)
E/flutter ( 6983): #17 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:382:19)
E/flutter ( 6983): #18 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
E/flutter ( 6983): #19 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)
E/flutter ( 6983):
Lost connection to device.