flutterandroid-cameraflutter-image

Can we change camera zoom point in flutter?


I work on a Flutter app in which I use camera plugin. I want to zoom in to an arbitrary point (offset) of the camera preview, for example to the top-left corner of the screen and then take a photo of it. Using CameraContoroller.setZoomLevel() method zooms into the center of the camera! Is it possbile to achieve the behavior that I want? Thank you in advance!

Here is what I want to achieve!

enter image description here


Solution

  • Unfortunately your wanted behavior is probably not possible with the camera packages. That is because the camera itself can not zoom into a specific area of its view, because of the way how zooming works with the hardware.

    But there are ways to achieve your expected behavior. Try to wrap your CameraPreview with a OverflowBox and/or a ClipRect and position the Preview in a way, that only the part you want to zoom in is visible. But be aware, that you "zoom" only virtually this way, because the actual camera view wont change (the resulting cutout may be of worse quality).

    Basically you are creating the illusion of a zoom, by cropping the image to the expected area.

    You can view specific code examples, on how you can implement this functionality in this answer.

    Keep in mind that if you want to take a picture of the "zoomed" area, you have to crop the resulting image again (because the actual camera view doesn't change), as explained in the question above.