Get the URI of an image stored in drawable
You should use ContentResolver
to open resource URIs:
Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name");
InputStream stream = getContentResolver().openInputStream(uri);
Also you can open file and content URIs using this method.
How to get path from image on drawable folder and set as image view, Bitmap?
You can save Reference Id R.drawable.img_name
as integer rather than saving path.
When you need to manipulate this drawable you can use that id instead of R.drawable.img_name
.
If you need a bitmap from this drawable follow this
Bitmap icon = BitmapFactory.decodeResource(context.getResources(),
saved_id);
Retrieve drawable resource from Uri
getContentResolver cr object
then call:
is = cr.openInputStream(uri)
and finally call:
Drawable.createFromStream(InputStream is, String srcName)
...Here's an actual working code example so you can see for yourself:
try {
InputStream inputStream = getContentResolver().openInputStream(yourUri);
yourDrawable = Drawable.createFromStream(inputStream, yourUri.toString() );
} catch (FileNotFoundException e) {
yourDrawable = getResources().getDrawable(R.drawable.default_image);
}
How to save a selected Uri pic to drawable?
Check out this link Retrieve drawable resource from Uri
try {
InputStream inputStream = getContentResolver().openInputStream(yourUri);
yourDrawable = Drawable.createFromStream(inputStream, yourUri.toString() );
imageView.setImageDrawable(yourDrawable);
} catch (FileNotFoundException e) {
yourDrawable = getResources().getDrawable(R.drawable.default_image);
}
Related Topics
Unresolved Reference - Activity Does Not Recognize Synthetic Imports in Android Studio V4
How to Get Text on an Actionbar Icon
Android Canvas: Draw Transparent Circle on Image
How to Check the Internet Connection in Android
How to Use Single Textwatcher for Multiple Edittexts
Single Selection in Recyclerview
Passing Data Between Activities in Android
Android Webview Rem Units Scale Way to Large for Boxes
Keyboard Showed Messed Up Elements' Position
Trusting All Certificates with Okhttp
How to Generate Class Diagram (Uml) on Android Studio (Intellij Idea)
Scale Factor for Xxhdpi Android
How to Download the Android Sdk Without Downloading Android Studio
Connectivitymanager.Connectivity_Action Deprecated
Camera Orientation Issue in Android