I’m new to Flutter. With flutter web I’m trying to make a web application that allows me to use the camera. I want to be able to detect the user’s face. I have a flask code that takes care of this, but to do so it needs a series of images that I’d like to send it from flutter. When I try to retrieve the image, it returns a blob link that opens another window to my application. So I can’t retrieve the image.
I’ve tried image picker web, imagepicker, camera as plugins but I still have the same problem.
here I initialize the camera :
startCamera() async {
_cameras = await availableCameras();
_controller = CameraController(_cameras[0], ResolutionPreset.high,
enableAudio: false);
_initializeControllerFuture = _controller.initialize();
_controller.initialize().then((_) {
// _controller.startImageStream(image);
if (!mounted) {
return;
}
setState(() {});
}).catchError((Object e) {
if (e is CameraException) {
switch (e.code) {
case 'CameraAccessDenied':
// Handle access errors here
break;
default:
// Handle other errors here
break;
}
}
});
}
This is the code that takes the picture in the Onpress method of a button:
final ImagePicker _picker = ImagePicker();
// Ensure that the camera is initialized.
await _initializeControllerFuture;
// Attempt to take a picture and get the file `image`
// where it was saved.
final image = await _controller.takePicture();
var selected = io.File(image.path);
print("this is the selected path" + image.path);
This is what i get in the console :
this is the selected path blob:http://localhost:49318/bdd2-002c0374c3c6
can you please help me? I’ve been working on it for several days now
2
Answers
I hope I understood you correctly. So you retrieve the image as the blob format because it is an Image from the web. As stated in this answer, the web platform does not support the
dart:io
package. To Display it you’ll need to useWhen u want to save the image, you need to decode the image to BASE64.
So you’ll get something like:
Now you can do whatever you want with the image.
Here’s my solution:
Decode the captured image to
ui.image
:Draw the
ui.image
withCustomPainter
:Render a
CustomPaint
widget withMyPainter
:You can also try my source code and online demo.