获取Drawable目录下的资源
/**
* 通过文件名获取Drawable目录下的图片资源
*
* @param context 上下文对象
* @param name 文件名
* @return bitmap
*/
public static Bitmap getDrableImage(Context context, String name) {
ApplicationInfo info = context.getApplicationInfo();
Resources resources = context.getResources();
int resId = resources.getIdentifier(name, "drawable", info.packageName);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
return BitmapFactory.decodeResource(resources, resId, options);
}
/**
* 获取drawable目录下的图片Uri
*
* @param name 文件名
* @return 文件对应的uri
*/
public static Uri getImageUri(Context context, String name) {
return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/drawable/" + name);
}