Wednesday, August 26, 2015

[Android] Convert uri to bitmap

Do not use toString().
uripath.toString()

Use getEncodedPath() get the encoded uri path, gives you an encoded string.
uripath.getEncodedPath()

I use BitmapFactory to convert uri file to bitmap :
Bitmap bitmap = BitmapFactory.decodeFile(cacheDir.getEncodedPath());
avatarView.setImageBitmap(bitmap);

Reference:
http://stackoverflow.com/questions/7022306/uri-tostring-returns-a-reference-instead-of-the-string
http://developer.android.com/reference/android/net/Uri.html#getEncodedPath()

No comments :

Post a Comment