Android 资源名资源id互转,根据路径获取bitmap跟drawable

1.根据资源名获取资源ID(name:资源名;"drawable":资源类型;"entry.dsa":包名)

int imgID = getResources().getIdentifier(name, "drawable","entry.dsa");


2.根据资源id转Drawable

Drawable drawable = getResources().getDrawable(imgID);


3.根据路径获取Bitmap

Bitmap bm = BitmapFactory.decodeFile(path);


4.Bitmap转Drawable
Drawable drawable = new BitmapDrawable(bm); 

你可能感兴趣的:(android)