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