Get a summary of picture resources

Source: Internet
Author: User

//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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.