CameraView icon indicating copy to clipboard operation
CameraView copied to clipboard

Flag to freeze camera preview during picture capturing

Open arsonistAnt opened this issue 5 years ago • 9 comments

How do I?

I've been reading through the docs and didn't see any mentions of being able to freeze/pause the frame of the camera view.

All I want to do is have the user capture an image and freeze the preview afterwards.

Is this possible with CamerView?

Version used

CameraView exact version.

arsonistAnt avatar Jun 07 '19 21:06 arsonistAnt

@natario1 Could this be easy as calling .stopPreview() in .takePicture(), and then .startPreview() in the onPictureResult callback? I just tried, and it seems to work.

I can send a PR if you want. Would you then in Camera1.java prefer to add a method takePictureAndStopPreview(), or takePicture(boolean stopPreview)?

hanspeide avatar Jun 08 '19 13:06 hanspeide

Alternatively methods .stopPreview() and .startPreview() can be exposed in CameraView.java. That might be a better solution?

hanspeide avatar Jun 08 '19 13:06 hanspeide

I think exposing the .stopPreview() and .startPreview() method would be better rather than combining the takePicture and stopPreview functionality together.

*UPDATE: Thanks to @hanspeide's suggestion, I was able to figure out how to expose the stopPreview() and startPreview() functions and make it available in the CameraView class. Its kind of hacky and doesn't really follow the MVC pattern that's established in this code base. Once I find a better way to pipe the functions from Camera1 to CameraView I guess I can share or attempt a pull request?

arsonistAnt avatar Jun 08 '19 13:06 arsonistAnt

Thanks! I disagree with introducing a new camera state with the whole confusion it brings in, for just a few usages, when there's a super easy solution already - take the picture / picture snapshot, and set it as a drawable to an ImageView on top of CameraView so it's covered.

natario1 avatar Jun 09 '19 15:06 natario1

@natario1 My issue here is the (obvious) delay between calling .takePicture() and receiving the result in onPictureTaken(). For UX reasons I would like to freeze the frame preview once .takePicture() is called, to prevent the user from thinking the camera is still active after taking a picture.

Were you think about taking the picture and snapshot sequentially, and then setting the snapshot as the ImageView drawable? From what I can tell it doesn't seem to work. An alternative would be to first call takeSnapshot(), then in onPictureTaken() check for result.isSnapshot, and if it is a snapshot call takePicture(). But, that doesn't feel very elegant either.

hanspeide avatar Jun 10 '19 21:06 hanspeide

I don't remember atm if you can call both together in new version, but if not, yes, snapshot first! The snapshot latency can be extremely low.

For "elegance" I would ignore snapshots in your main callback, and use a one-time callback just for the snapshot.

But keep an eye on here, at some point we can make this possible in other ways (let you subclass some component so you can avoid drawing, for example), I just don't like the idea of a frozen state.

natario1 avatar Jun 10 '19 21:06 natario1

Another option is use the FrameProcessor to get the latest frame when shooting, that's the faster thing but it doesn't come in JPEG, prob. decoding it takes more time but I don't really know.

natario1 avatar Jun 10 '19 21:06 natario1

What I can accept as a PR is give the developer a boolean option, that if true, freezes the preview during the time between take and onTaken.

Tecnhically this should be done in the Preview classes (avoid drawing) rather than tearing the preview down with stopPreview.

natario1 avatar Jun 10 '19 21:06 natario1

This issue has been automatically marked as stale because it has not had activity in the last 20 days. It will be closed if no further activity occurs within the next seven days. Thank you for your contributions.

stale[bot] avatar Jun 30 '19 22:06 stale[bot]