//1, the picture has been saved to the drawable directory//get drawable by Image IDResource Res=Gerresource ();D rawable drawable=res.getdrawable (ID);//ID is r.drawable. Picture name//get bitmap by Image IDResource Res=Gerresource (); Bitmap Bitmap=Bitmapfactory.decoderesource (res, id);//If you only know the name of the picture, you can get the image ID by the name of the picture.//Name: Picture Deftype: The type of picture (Png,jpeg), Defpackage: Project's package nameintID =intID =res.getidentifier (name, Deftype, defpackage);//after obtaining the ID, you can get bitmap or drawable according to your needs .//2, the picture has been saved to the Assest directory//know the name of the picture, open the picture by InputStreamAssetmanager ASM=getassetmg (); InputStream is=asm.open (name);//Name: title of picture//Get drawabledrawable da = Drawable.createfromstream (IS,NULL);//Get bitmapBitmap bitmap=Bitmapfactory.decodestream (IS);//3, Picture saved in SDcard, path of known picture//Picture PathString path = Environment.getexternalstoragedirectory (). toString () + "/dcim/device.png"; Randomaccessfile mminithumbfile;file Imgfile=NewFile (path);Try{mminithumbfile=NewRandomaccessfile (Imgfile, "RW");} Catch(IOException ex) {//Open as Read-only so we can at least read the existing//thumbnails.Try{mminithumbfile=NewRandomaccessfile (Imgfile, "R");} Catch(IOException ex2) {//Ignore ExceptionSystem.out.println (ex2.tostring ());}} Data=New byte[10553];Try{Mminithumbfile.seek (0);intGot = Mminithumbfile.read (data, 0, 10552); System.out.println ("Got=" +got);} Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); System.out.println (E.tostring ());}if(Data! =NULL) {//get bitmap with DataBitmap Bitmap = Bitmapfactory.decodebytearray (data, 0,data.length);
Get a summary of picture resources