獲取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);
}