Examples of bitmap usage of Android learning

Source: Internet
Author: User

The following is a brief description of the use of bitmap:

Download a picture from the server, display it on the ImageView control, and save the picture on your mobile device's SD.

1 //get input stream based on network URL2      PublicInputStream Geturlinputstream (String strurl)throwsIOException {3URL url =NewURL (strurl);4HttpURLConnection conn =(HttpURLConnection) url.openconnection ();5InputStream InputStream =Conn.getinputstream ();6         if(InputStream! =NULL) {7             returnInputStream;8}Else {9LOG.I ("InputStream", "input stream object is empty");Ten             return NULL; One         } A     } -  -     //flow input into bitmap stream the      PublicBitmap Getbitmap (InputStream inputstream) { -Bitmap Bitmap =NULL; -         if(InputStream! =NULL) { -Bitmap =Bitmapfactory.decodestream (inputstream); +             returnbitmap; -}Else { +LOG.I ("Test", "input stream object in is empty"); A             return NULL; at         } -     } -  -     //Assigning a value to a ImageView object -      Public voidsetwidgetimage (Bitmap Bitmap) { -ImageView img =NewImageView ( This); in         if(Bitmap! =NULL) { - Img.setimagebitmap (bitmap); to         } +     } -  the     //get the file storage path on the SD card *      Public voidCreatesdfile () { $File Sdroot =environment.getexternalstoragedirectory ();Panax NotoginsengFile File =NewFile (Sdroot + "/android/date/package name/file name"); -         if(Environment.MEDIA_MOUNTED.equals (Environment the . Getexternalstoragestate ())) { +             //Related Actions A         } the     } +  -     //Save the picture to an SD card $      Public Booleanreadtosdcard (file file, Bitmap Bitmap) $             throwsFileNotFoundException { -FileOutputStream OS =Newfileoutputstream (file); -         returnBitmap.compress (Bitmap.CompressFormat.PNG, 90, OS); the         //true: Indicates operation succeeded, false: operation failed -}

Examples of bitmap usage of Android learning

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.