fix third party intent image capturing

This commit is contained in:
tibbi 2018-06-14 13:04:46 +02:00
parent 22ed7a2678
commit 854a865071
3 changed files with 18 additions and 8 deletions

View File

@ -18,7 +18,8 @@ import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.io.OutputStream
class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOrientation: Int, val previewRotation: Int, val isUsingFrontCamera: Boolean) :
class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOrientation: Int, val previewRotation: Int, val isUsingFrontCamera: Boolean,
val isThirdPartyIntent: Boolean) :
AsyncTask<ByteArray, Void, String>() {
override fun doInBackground(vararg params: ByteArray): String {
@ -67,14 +68,21 @@ class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOr
}
}
val exif = ExifInterface(photoFile.toString())
val orient = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
val exif = try {
ExifInterface(path)
} catch (e: Exception) {
null
}
val orient = exif?.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
?: ExifInterface.ORIENTATION_UNDEFINED
val imageRot = orient.degreesFromOrientation()
val deviceRot = compensateDeviceRotation(deviceOrientation, isUsingFrontCamera)
var image = BitmapFactory.decodeByteArray(data, 0, data.size)
val totalRotation = (imageRot + deviceRot + previewRotation) % 360
if (path.startsWith(activity.internalStoragePath) || isNougatPlus()) {
if (path.startsWith(activity.internalStoragePath) || isNougatPlus() && !isThirdPartyIntent) {
// do not rotate the image itself in these cases, rotate it by exif only
} else {
// make sure the image itself is rotated at third party intents
@ -98,13 +106,15 @@ class PhotoProcessor(val activity: MainActivity, val saveUri: Uri?, val deviceOr
try {
image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos)
activity.saveImageRotation(path, totalRotation)
if (!isThirdPartyIntent) {
activity.saveImageRotation(path, totalRotation)
}
} catch (e: Exception) {
activity.showErrorToast(e)
return ""
}
if (activity.config.savePhotoMetadata) {
if (activity.config.savePhotoMetadata && !isThirdPartyIntent) {
val fileExif = ExifInterface(path)
tempExif.copyTo(fileExif)
}

View File

@ -383,7 +383,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
private fun storePhoto(data: ByteArray) {
val previewRotation = getPreviewRotation(mCurrCameraId)
PhotoProcessor(mActivity!!, mTargetUri, mRotationAtCapture, previewRotation, getIsUsingFrontCamera()).execute(data)
PhotoProcessor(mActivity!!, mTargetUri, mRotationAtCapture, previewRotation, getIsUsingFrontCamera(), mIsImageCaptureIntent).execute(data)
}
private fun getIsUsingFrontCamera() = mCurrCameraId == mActivity!!.getMyCamera().getFrontCameraId()

View File

@ -275,7 +275,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
val buffer = reader.acquireNextImage().planes.first().buffer
val bytes = ByteArray(buffer.remaining())
buffer.get(bytes)
PhotoProcessor(mActivity, mTargetUri, mRotationAtCapture, mSensorOrientation, mUseFrontCamera).execute(bytes)
PhotoProcessor(mActivity, mTargetUri, mRotationAtCapture, mSensorOrientation, mUseFrontCamera, mIsImageCaptureIntent).execute(bytes)
} catch (e: Exception) {
}
}