是否可以在不调用 getContentResolver() 的情况下从 Uri 检索位图?
Is it possible to retrieve a Bitmap from a Uri without calling getContentResolver()?
我是 Android 的新手,抱歉,如果我的问题没有多大意义,但我已经搜索了很多,但还不能说清楚。
我有一个 Item 对象,它是使用从 sqlite 数据库中提取的数据构建的。此项目的字段之一是位图(在数据库中存储为 Uri),应从项目构造函数中的 Uri 创建。
当我尝试在构造函数中执行以下操作时,我得到 java.io.FileNotFoundException: No package found for authority: android.resource://com.my.package/drawable/theImage
:
try {
actualPic = MediaStore.Images.Media.getBitmap(app.getContentResolver(), theImageUri);
} catch (IOException e) {
e.printStackTrace();
}
重要提示:MainActivity class 实例化 Item 对象,将对自身的引用传递给名为 app 的 Item 构造函数,我用它来调用 getContentResolver 方法。
我读到我需要制作一个 class 来扩展 ContentProvider 并在清单中声明它,但要获得该 Bitmap 似乎还有很多工作要做。我错过了什么吗?是否有更简单的方法来检索该位图,或者我需要创建新的 class?
提前致谢。
如果您只想从资源中检索位图,请检查:How to convert a Drawable to a Bitmap?
我是 Android 的新手,抱歉,如果我的问题没有多大意义,但我已经搜索了很多,但还不能说清楚。
我有一个 Item 对象,它是使用从 sqlite 数据库中提取的数据构建的。此项目的字段之一是位图(在数据库中存储为 Uri),应从项目构造函数中的 Uri 创建。
当我尝试在构造函数中执行以下操作时,我得到 java.io.FileNotFoundException: No package found for authority: android.resource://com.my.package/drawable/theImage
:
try {
actualPic = MediaStore.Images.Media.getBitmap(app.getContentResolver(), theImageUri);
} catch (IOException e) {
e.printStackTrace();
}
重要提示:MainActivity class 实例化 Item 对象,将对自身的引用传递给名为 app 的 Item 构造函数,我用它来调用 getContentResolver 方法。
我读到我需要制作一个 class 来扩展 ContentProvider 并在清单中声明它,但要获得该 Bitmap 似乎还有很多工作要做。我错过了什么吗?是否有更简单的方法来检索该位图,或者我需要创建新的 class?
提前致谢。
如果您只想从资源中检索位图,请检查:How to convert a Drawable to a Bitmap?