fix third party intent image capturing
This commit is contained in:
parent
22ed7a2678
commit
854a865071
|
@ -18,7 +18,8 @@ import java.io.FileNotFoundException
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.OutputStream
|
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>() {
|
AsyncTask<ByteArray, Void, String>() {
|
||||||
|
|
||||||
override fun doInBackground(vararg params: ByteArray): 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 exif = try {
|
||||||
val orient = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
|
ExifInterface(path)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
|
val orient = exif?.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED)
|
||||||
|
?: ExifInterface.ORIENTATION_UNDEFINED
|
||||||
|
|
||||||
val imageRot = orient.degreesFromOrientation()
|
val imageRot = orient.degreesFromOrientation()
|
||||||
|
|
||||||
val deviceRot = compensateDeviceRotation(deviceOrientation, isUsingFrontCamera)
|
val deviceRot = compensateDeviceRotation(deviceOrientation, isUsingFrontCamera)
|
||||||
var image = BitmapFactory.decodeByteArray(data, 0, data.size)
|
var image = BitmapFactory.decodeByteArray(data, 0, data.size)
|
||||||
val totalRotation = (imageRot + deviceRot + previewRotation) % 360
|
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
|
// do not rotate the image itself in these cases, rotate it by exif only
|
||||||
} else {
|
} else {
|
||||||
// make sure the image itself is rotated at third party intents
|
// 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 {
|
try {
|
||||||
image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos)
|
image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos)
|
||||||
activity.saveImageRotation(path, totalRotation)
|
if (!isThirdPartyIntent) {
|
||||||
|
activity.saveImageRotation(path, totalRotation)
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
activity.showErrorToast(e)
|
activity.showErrorToast(e)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity.config.savePhotoMetadata) {
|
if (activity.config.savePhotoMetadata && !isThirdPartyIntent) {
|
||||||
val fileExif = ExifInterface(path)
|
val fileExif = ExifInterface(path)
|
||||||
tempExif.copyTo(fileExif)
|
tempExif.copyTo(fileExif)
|
||||||
}
|
}
|
||||||
|
|
|
@ -383,7 +383,7 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
|
||||||
|
|
||||||
private fun storePhoto(data: ByteArray) {
|
private fun storePhoto(data: ByteArray) {
|
||||||
val previewRotation = getPreviewRotation(mCurrCameraId)
|
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()
|
private fun getIsUsingFrontCamera() = mCurrCameraId == mActivity!!.getMyCamera().getFrontCameraId()
|
||||||
|
|
|
@ -275,7 +275,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
||||||
val buffer = reader.acquireNextImage().planes.first().buffer
|
val buffer = reader.acquireNextImage().planes.first().buffer
|
||||||
val bytes = ByteArray(buffer.remaining())
|
val bytes = ByteArray(buffer.remaining())
|
||||||
buffer.get(bytes)
|
buffer.get(bytes)
|
||||||
PhotoProcessor(mActivity, mTargetUri, mRotationAtCapture, mSensorOrientation, mUseFrontCamera).execute(bytes)
|
PhotoProcessor(mActivity, mTargetUri, mRotationAtCapture, mSensorOrientation, mUseFrontCamera, mIsImageCaptureIntent).execute(bytes)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue