Open VincentJoshuaET opened 3 years ago
Meanwhile we can create the cache file manually
fun getCachedImage(uri: Uri): String {
val compressedFile = File(externalCacheDir, "picked/IMG_${SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())}.png")
Timber.d("compressedFile: ${compressedFile.path}")
val originalScaleOptions = BitmapFactory.Options()
val stream = this.contentResolver.openInputStream(uri)
val oBitmap = BitmapFactory.decodeStream(stream, null, originalScaleOptions)
val byteArrayOutputStream = ByteArrayOutputStream()
oBitmap?.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream)
val fileOutputStream = FileOutputStream(compressedFile)
fileOutputStream.write(byteArrayOutputStream.toByteArray())
fileOutputStream.flush()
fileOutputStream.close()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val oExif = ExifInterface(stream!!)
val nExif = ExifInterface(compressedFile)
val ogOr = oExif.getAttribute(ExifInterface.TAG_ORIENTATION)
nExif.setAttribute(ExifInterface.TAG_ORIENTATION, ogOr)
nExif.setAttribute(ExifInterface.TAG_EXIF_VERSION, oExif.getAttribute(ExifInterface.TAG_EXIF_VERSION))
nExif.saveAttributes()
}
return compressedFile.path
}
If I call
saveDir(DIRECTORY)
withgalleryOnly()
AND withoutcrop*()
ORcompress()
, we should be able to choose if we want to copy the selected image into the directory, so that we can get a File URI instead of a Content URI.