Resources res= getResources();
//1,已将图片保存到drawable目录下
//通过图片id获得Drawable
Drawable drawable=res.getDrawable(R.drawable.loginimage1);//id为R.drawable.图片名称
//通过图片id获得Bitmap
Bitmap bitmap=BitmapFactory.decodeResource(res, R.drawable.loginimage1);
//若只知道图片的名称,可以通过图片的名称获得图片的id
//name:图片的名称defType:图片的类型(png,jpeg),defPackage:工程的包名
int id = res.getIdentifier("imagename", "png", "com.yym.demo");
//获得id之后可以根据你的需要来获得Bitmap或Drawable
//2,已将图片保存到assest目录下
//知道图片的名称,通过inputstream打开图片
AssetManager asm= getAssets();
InputStream is=asm.open("imagename");//name:图片的名称
//获得Drawable
Drawable da = Drawable.createFromStream(is, null);
//获得Bitmap
Bitmap bitmap1 = BitmapFactory.decodeStream(is);
//1,已将图片保存到drawable目录下
//通过图片id获得Drawable
Drawable drawable=res.getDrawable(R.drawable.loginimage1);//id为R.drawable.图片名称
//通过图片id获得Bitmap
Bitmap bitmap=BitmapFactory.decodeResource(res, R.drawable.loginimage1);
//若只知道图片的名称,可以通过图片的名称获得图片的id
//name:图片的名称defType:图片的类型(png,jpeg),defPackage:工程的包名
int id = res.getIdentifier("imagename", "png", "com.yym.demo");
//获得id之后可以根据你的需要来获得Bitmap或Drawable
//2,已将图片保存到assest目录下
//知道图片的名称,通过inputstream打开图片
AssetManager asm= getAssets();
InputStream is=asm.open("imagename");//name:图片的名称
//获得Drawable
Drawable da = Drawable.createFromStream(is, null);
//获得Bitmap
Bitmap bitmap1 = BitmapFactory.decodeStream(is);