Skip to content

Instantly share code, notes, and snippets.

@cdmunoz
Created October 22, 2019 02:28
Show Gist options
  • Save cdmunoz/fe93be9572d7994fbc3d04c2717f7291 to your computer and use it in GitHub Desktop.
Save cdmunoz/fe93be9572d7994fbc3d04c2717f7291 to your computer and use it in GitHub Desktop.
fun savePickedImage(activity: Activity) {
val bm = BitmapFactory.decodeResource(activity.resources, R.mipmap.ic_launcher)
val dir = activity.externalCacheDir
val file = File(dir?.path, "pickImageResult.jpeg")
val outStream: FileOutputStream?
try {
outStream = FileOutputStream(file)
bm.compress(Bitmap.CompressFormat.JPEG, 100, outStream)
with(outStream) {
flush()
close()
}
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment