1. Picture in SDcard
Bitmap imagebitmap = bitmapfactory.decodefile (path) (paths are images, and directories are/sdcard)
2. Picture below the Res folder of the project
Get Application Object
ApplicationInfo appInfo = Getapplicationinfo ();
Get the image ID (name is the name of the picture, "Drawable" is the directory where the picture is stored, Appinfo.packagename is the app's package)
int resID = Getresources (). Getidentifier (Name, "drawable", appinfo.packagename);
The code is as follows
Public Bitmap getres (String name) {
ApplicationInfo appInfo = Getapplicationinfo ();
int resID = Getresources (). Getidentifier (Name, "drawable", appinfo.packagename);
Return Bitmapfactory.decoderesource (Getresources (), ResID);
}
3. The image is placed in the SRC directory
String Path = "Com/xiangmu/test.png"; Path of picture storage
InputStream is = getClassLoader (). getResourceAsStream (path); Get picture Stream
There is a assets directory in 4.android, where you can store read-only files
The way resources are obtained is
InputStream is = Getresources (). Getassets (). open (name);
4 ways to get picture resources on Android