Do an Android scratch-scratch project today. It used a lot of places to use the getresources.
<span style= "FONT-SIZE:12PX;" >//get Picture//Parameter 1:res is a reference to the resource, the 2:id is the idafter of the picture = Bitmapfactory.decoderesource (Getresources (), r.drawable.b); before = Bitmapfactory.decoderesource (Getresources (), R.drawable.a);</span>
At first, it was not quite understood why the Getresources () method could be used to obtain the resources of the existing system.
So I looked at the document and read the information:
Packet Package:android.content.res
Main categories: Resources
InputStream openrawresource (int id) gets the data stream of the resource, reads the resource data
Put a picture resource. Add your files to your project in the res/drawable/folder and from here you will be able to reference it to your code or your XML layout, that is to say. Referencing it can also be used as a resource number. For example, if you choose a file, you can simply remove the suffix (e.g. my_image.png refers to it is my_image).
When you need to use XML resources. will be able to use Context.getresources (). getdrawable (R .... The address of the resource such as: R.string.ok);
When you do not have a context parameter inside your method, you can This.getcontext (). Getresources ();
Note that when using getresource (), note
1, must have the context
2, can be used as a member variable, constructs an incoming or method parameter incoming. will be able to.
Put the resource file under the/raw/raw of the application
After you use Getresources in your app to get resources. Open the file with the Openrawresource method (the name of the resource file without the suffix). Like what:
Resources myresources = Getresources (); InputStream myFile = Myresources.openrawresource (r.raw.myfilename);
As with traditional Java file operations, the Openfileinput and Openfileoutput methods are available in the Android API to read files on the device.
InputStream FS =this.getresources (). Openrawresource (R.RAW.KB); (The resource file name is called kb.html and does not require a suffix. html) InputStreamReader read = new InputStreamReader (FS, "Gb2312″");
read PNG or BMG under the Res/drawable folder
Get Resources Object r = This.getcontext (). Getresources (); Reads a resource as a data stream InputStream is = R.openrawresource (r.drawable.my_background_image); Bitmapdrawable Bmpdraw = new Bitmapdrawable (is); Bitmap bmp = Bmpdraw.getbitmap ();
Method 2:
InputStream is = Getresources (). Openrawresource (R.drawable.icon); Bitmap Mbitmap = Bitmapfactory.decodestream (is); Paint Mpaint = new paint (); Canvas.drawbitmap (Mbitmap, Max, mpaint);
Zhao Yazhi _android's getresources () resource reference