add photo saving with Camera2 api
This commit is contained in:
parent
a894f6e01c
commit
49bd2b1be9
|
@ -9,7 +9,10 @@ import android.os.AsyncTask
|
|||
import android.os.Environment
|
||||
import com.simplemobiletools.camera.R
|
||||
import com.simplemobiletools.camera.activities.MainActivity
|
||||
import com.simplemobiletools.camera.extensions.*
|
||||
import com.simplemobiletools.camera.extensions.compensateDeviceRotation
|
||||
import com.simplemobiletools.camera.extensions.config
|
||||
import com.simplemobiletools.camera.extensions.getOutputMediaFile
|
||||
import com.simplemobiletools.camera.extensions.getPreviewRotation
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||
import java.io.File
|
||||
|
@ -17,7 +20,7 @@ import java.io.FileNotFoundException
|
|||
import java.io.FileOutputStream
|
||||
import java.io.OutputStream
|
||||
|
||||
class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId: Int, val deviceOrientation: Int) : AsyncTask<ByteArray, Void, String>() {
|
||||
class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId: Int, val deviceOrientation: Int, val flipHorizontally: Boolean) : AsyncTask<ByteArray, Void, String>() {
|
||||
|
||||
override fun doInBackground(vararg params: ByteArray): String {
|
||||
var fos: OutputStream? = null
|
||||
|
@ -78,7 +81,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
|
|||
image = rotate(image, totalRotation)
|
||||
}
|
||||
|
||||
if (currCameraId == activity.getMyCamera().getFrontCameraId() && !activity.config.flipPhotos) {
|
||||
if (flipHorizontally) {
|
||||
val matrix = Matrix()
|
||||
if (path.startsWith(activity.internalStoragePath)) {
|
||||
matrix.preScale(1f, -1f)
|
||||
|
|
|
@ -383,7 +383,8 @@ class PreviewCameraOne : ViewGroup, SurfaceHolder.Callback, MyPreview {
|
|||
}
|
||||
|
||||
private fun storePhoto(data: ByteArray) {
|
||||
PhotoProcessor(mActivity!!, mTargetUri, mCurrCameraId, mRotationAtCapture).execute(data)
|
||||
val flipHorizontally = mActivity!!.config.flipPhotos && mCurrCameraId == mActivity!!.getMyCamera().getFrontCameraId()
|
||||
PhotoProcessor(mActivity!!, mTargetUri, mCurrCameraId, mRotationAtCapture, flipHorizontally).execute(data)
|
||||
}
|
||||
|
||||
private fun handlePreview() {
|
||||
|
|
|
@ -16,6 +16,7 @@ import android.view.Surface
|
|||
import android.view.TextureView
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.camera.activities.MainActivity
|
||||
import com.simplemobiletools.camera.extensions.config
|
||||
import com.simplemobiletools.camera.helpers.*
|
||||
import com.simplemobiletools.camera.interfaces.MyPreview
|
||||
import java.util.*
|
||||
|
@ -138,8 +139,17 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||
}
|
||||
|
||||
private val imageAvailableListener = ImageReader.OnImageAvailableListener { reader ->
|
||||
val image = reader.acquireNextImage()
|
||||
val buffer = image.planes[0].buffer
|
||||
val buffer = reader.acquireNextImage().planes[0].buffer
|
||||
val bytes = ByteArray(buffer.remaining())
|
||||
buffer.get(bytes)
|
||||
PhotoProcessor(mActivity, mTargetUri, 0, 0, mActivity.config.flipPhotos && getIsFrontCamera()).execute(bytes)
|
||||
}
|
||||
|
||||
private fun getIsFrontCamera(): Boolean {
|
||||
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
||||
val characteristics = manager.getCameraCharacteristics(mCameraId)
|
||||
val facing = characteristics.get(CameraCharacteristics.LENS_FACING)
|
||||
return facing == CameraCharacteristics.LENS_FACING_FRONT
|
||||
}
|
||||
|
||||
private fun setupCameraOutputs(width: Int, height: Int) {
|
||||
|
|
Loading…
Reference in New Issue