Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Sample Parameter:
- String: "file:///storage/emulated/0/Android/data/com.example.disappeardents/cache/roof_1.jpg"
- */
- fun uriStringToBitmap(uriString : String) : Bitmap {
- val uri = uriString.toUri()
- val uriPath = uri.path
- val bitmap = BitmapFactory.decodeFile(uriPath)
- return bitmap
- }
- /*
- Sample Parameter:
- 1: Bitmap: [bitmap]
- 2: String: "my_file_name.jpg"
- */
- fun bitmapToUriString(bitmap: Bitmap, fileName: String) : Uri{
- // set directory where it will be stored (on cache)
- var file = File(activity!!.externalCacheDir, fileName)
- // save the image on cache
- var fOut = FileOutputStream(file)
- bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fOut)
- // get the path of the image
- var uriPath = Uri.fromFile(file)
- return uriPath
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement