I don't have much experience working with the camera and files in general. I've integrated CameraKit's library to capture images, and this is my current code:
captureButton.setOnClickListener {
cameraKitView.captureImage() { _, p1 ->
val timeStamp = System.currentTimeMillis().toString()
val fileName = "Dere$timeStamp.jpg"
val path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString() + File.separator + "Dere"
val outputDir = File(path)
outputDir.mkdir()
val savedPhoto = File(path + File.separator + fileName)
try {
val outputStream = FileOutputStream(savedPhoto.path)
outputStream.write(p1)
outputStream.close()
mActivity.sendBroadcast(
Intent(
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.fromFile(savedPhoto)
)
)
// Here I'm already loading the image into an mage view for the user to apprve the photo
Glide.with(mActivity).load(savedPhoto)
.into(mActivity.photoEditorFragment.view!!.photo_editor_image)
// at this point I save this photo with some extra details that were collected to the local room database
val localImagePost = LocalImagePost(
timeStamp.toLong(),
location.longitude,
location.latitude,
savedPhoto.path,
"",
"",
true
)
localImageViewModel.insert(localImagePost)
sharedViewModelLocalImagePost.sharedImagePostObject.postValue(localImagePost)
} catch (e: java.io.IOException) {
e.printStackTrace()
}
}
}
P1 is a ByteArray. I've asked a question before here Can I get the orientation of a photo taken in my app if I limit the activity's orientation to portrait only in my manifest? but I can't figure out how and where to use it in my code. Do I create a brand new file FROM the first file I just created, and then delete the first one? Or do I just start off by creating the rotated file? I'm a bit lost, would appreciate any help, thanks!