Way One:
You have saved the picture to the drawable directory and obtained drawable or bitmap with the picture ID, which is most commonly used. (If you only know the name of the picture, you can also get the image ID by the name of the picture)
(1) Get drawable by Image ID
Drawable Drawable=getresource (). getdrawable (R.DRAWABLE.XXX);
(2) Get bitmap by Image ID
Resource Res=gerresource ();
Bitmap Bitmap=bitmapfactory.decoderesource (res, id);
(3) Get the ID of the picture by the name of the picture (two methods)
int ID =res.getidentifier (name, Deftype, defpackage); Name: The name of the picture, Deftype: Resource type (drawable,string ... ), Defpackage: Project's package name
Drawable Drawable=getresource (). getdrawable (ID);
Way two:
Saved the picture to the Assest directory, know the name of the picture, get the picture by InputStream Drawabl
or Bitmap.
Assetmanager ASM=GETASSETMG ();
InputStream Is=asm.open (name);//name: Name of the picture
(1) Get drawable
drawable da = Drawable.createfromstream (is, null);
(2) Get bitmap
Bitmap Bitmap=bitmapfactory.decodestream (IS);
Way three: Picture saved in SDcard, through the path of the picture H
/Picture Path
String Imgfilepath = Environment.getexternalstoragedirectory (). ToString ()
+ "/dcim/device.png";
(1) file input stream
FIS = new FileInputStream (new file (Imgfilepath));//File input stream
Bitmap bmp = Bitmapfactory.decodestream (FIS);
(2)
ImageView IV = (ImageView) Findviewbyid (r.id.image);
Bitmap bit = Bitmapfactory.decodefile ("/sdcard/android.bmp");
Iv.setimagebitmap (bit);
Iv.setimagedrawable (Drawable.createfrompath (New File (Environment.getexternalstoragedirectory (), "camera.jpg"). GetAbsolutePath ()));
Image resources for reading different locations (Drawable,asset,sdcard) in Android