[在旧的android相机api中,我们可以使用此方法删除图像中的GPS数据。(Camera.Parameters -> removeGpsData)
有人知道如何使用新的Android Camera2 API删除或禁用图像中的GPS数据吗?我们的目标是在图像的exif中拍摄没有gps信息的图片。
以下是我的代码:
private fun createCameraPreviewSession() {
try {
val texture = textureView.surfaceTexture
// We configure the size of default buffer to be the size of camera preview we want.
texture.setDefaultBufferSize(previewSize.width, previewSize.height)
// This is the output Surface we need to start preview.
val surface = Surface(texture)
// We set up a CaptureRequest.Builder with the output Surface.
previewRequestBuilder = cameraDevice!!.createCaptureRequest(
CameraDevice.TEMPLATE_PREVIEW
)
previewRequestBuilder.addTarget(surface)
// Here, we create a CameraCaptureSession for camera preview.
cameraDevice?.createCaptureSession(Arrays.asList(surface, imageReader?.surface),
object : CameraCaptureSession.StateCallback() {
override fun onConfigured(cameraCaptureSession: CameraCaptureSession) {
// The camera is already closed
if (cameraDevice == null) return
// When the session is ready, we start displaying the preview.
captureSession = cameraCaptureSession
try {
// Auto focus should be continuous for camera preview.
previewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
// Flash is automatically enabled when necessary.
setAutoFlash(previewRequestBuilder)
// Finally, we start displaying the camera preview.
previewRequest = previewRequestBuilder.build()
captureSession?.setRepeatingRequest(previewRequest,
captureCallback, backgroundHandler)
} catch (e: CameraAccessException) {
Log.e(TAG, e.toString())
}
}
override fun onConfigureFailed(session: CameraCaptureSession) {
activity.showToast("Failed")
}
}, null)
} catch (e: CameraAccessException) {
Log.e(TAG, e.toString())
}
}
经过一天的学习,终于找到了解决方案。