How can I add zoom in/out gesture in Android vision CameraSource

最后都变了- 提交于 2019-12-11 04:37:59

问题


I'm trying to develop a simple camera app with face detection and i'm using android-vision sample from here https://github.com/googlesamples/android-vision/tree/master/visionSamples/FaceTracker

Everything is working fine and i need to add zoom in/out feature in it. I searched SO but found nothing related to vision. Every answer is related to Camera2.


回答1:


You might try startSmoothZoom:

https://developer.android.com/reference/android/hardware/Camera.html#startSmoothZoom(int)

You'd need to modify the open source version of CameraSource to make this change, since you'd need access to its underlying android.hardware.Camera instance:

https://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java#L121




回答2:


Try this code, it works (Yes, it's reflection)

try {
    cameraSource.apply {
        start(holder)
        javaClass.getDeclaredField("zzg").apply {
            isAccessible = true
            (get(cameraSource) as Camera).apply {
                startSmoothZoom(min(5, parameters.maxZoom))
            }
        }
    }
} catch (e: Throwable) {
    Timber.e(e)
}

Notice, that zzg is an obfuscated var of Camera instance and it's name may be different per library releases



来源:https://stackoverflow.com/questions/40783903/how-can-i-add-zoom-in-out-gesture-in-android-vision-camerasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!