简体   繁体   中英

Is it possible to retrieve a Bitmap from a Uri without calling getContentResolver()?

I'm new to Android, sorry if my question doesn't make a lot of sense, but I've searched a lot and could't make this clear yet.

I have an Item object, that gets build with data pulled from an sqlite db. One of this Item's fields is a Bitmap (stored as a Uri in the DB) that should be created from the Uri in the Item's constructor.

I'm getting java.io.FileNotFoundException: No package found for authority: android.resource://com.my.package/drawable/theImage when I try to do the following in the constructor:

try {
     actualPic = MediaStore.Images.Media.getBitmap(app.getContentResolver(), theImageUri);
} catch (IOException e) {
     e.printStackTrace();
}

IMPORTANT: MainActivity, which is the class instantiating the Item object, passes a reference to itself to the Item's constructor called app, which I use to call getContentResolver method.

I read that I need to make a class that extends ContentProvider and declare it in the manifest, but it seems like aa lot to do to just get that Bitmap. Am I missing something? Is there a simpler way of getting that Bitmap retrieved or I need to create that new class?

Thanks in advance.

如果只想从资源中检索位图,请检查以下内容: 如何将Drawable转换为位图?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM