RedApparat / Fotoapparat

Making Camera for Android more friendly. đŸ“¸
Apache License 2.0
3.81k stars 405 forks source link

Question/Suggestion - freeze frame preview on demand #369

Closed FrenzyPancake closed 5 years ago

FrenzyPancake commented 5 years ago

What are you trying to achieve or the steps to reproduce?

After taking the picture I'm doing some bitmap manipulation (merging with other bitmaps) on the fly, because of that I wanted to freeze preview during capture so the user can see what more or less the result will look like, but cannot find a way to do it correctly.

Looking at your api only thing that comes to my mind is to attach frame processor and get frame when I'm calling take picture and display it on overlayed ImageView, but this takes way too long, bitmap decoding, rotation and loading it to view, around 0,5 second to show on screen.

I cannot wait for photo result because of it's much larger size than the preview, so rotation alone on final bitmap takes like half a second.

How did you initialize FA?

    private fun prepareFotoApparat() {
        val configuration = CameraConfiguration.builder()
                .previewResolution(getHighestResolution(DEFAULT_ASPECT_RATIO))
                .photoResolution(getHighestResolution(DEFAULT_ASPECT_RATIO))
                .frameProcessor(object : FrameProcessor {
                    override fun process(frame: Frame) {
                        if (freezeFrame) {
                            frame.display()
                            freezeFrame = false
                        }
                    }
                }).build()

        fotoapparat = Fotoapparat(
                context = requireContext(),
                view = binding.cameraView,
                scaleType = ScaleType.CenterInside,
                lensPosition = back(),
                cameraConfiguration = configuration,
                logger = if (BuildConfig.DEBUG) logcat() else none(),
                cameraErrorCallback = { error ->
                    Timber.e(error)
                }
        )
    }

What was the result you received?

It was too slow to load frame from frameProcessor to separate view

What did you expect?

It would be awesome to able to call something like stop() on preview, or attach some kind of transformation that would get frames before they are displayed so I could just freeze on chosen one if I need that.

Actualy calling stop on fotoapparat object does exactly what I need, but it also stops all image processing in the background so I cannot receive a picture after calling it.

FrenzyPancake commented 5 years ago

After some performance tests, actually sample code works good fine, take a picture and display it in ImageView. One caveat here, if the rotation is 90 or 270 and ImageView for example full screen then the size of the ImageView has to be swapped for it be displayed correctly.