You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
privatesuspendfunpersistBitmapToInternalStorage(context:Context, image:Bitmap): File? {
return withContext(Dispatchers.Default) {
val contextWrapper =ContextWrapper(context)
val screenshotDirectory =
contextWrapper.getDir(SCREENSHOT_LOCAL_DIR, Context.MODE_PRIVATE)
val screenshotFile =File(screenshotDirectory, "${System.currentTimeMillis()}.jpg")
if (!screenshotFile.exists()) {
try {
val fos =FileOutputStream(screenshotFile)
image.compress(Bitmap.CompressFormat.JPEG, 80, fos)
fos.flush()
fos.close()
return@withContext screenshotFile
} catch (e:Exception) {
Crash.log(
this::class,
"Error while transform Bitmap to persistent file on local storage",
e
)
return@withContext null
}
} else {
Crash.log(
this::class,
"The filename already exist in local storage => Barely impossible, because name is generated from actual timestamp millis"
)
return@withContext screenshotFile
}
}
}