ImageView is a frequently used component of an Android program that displays a picture on the screen. A imageview is defined in the UI XML as follows:
Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.myimage); ImageView Image1=(ImageView) Findviewbyid (r.myimage.image); //Bitmap Bitmap = Getloacalbitmap ("/aa/aa.jpg");//take pictures from localBitmap Bitmap =Gethttpbitmap ("Http://blog.3gstdy.com/wp-content/themes/twentyten/images/headers/path.jpg");//take pictures from the InternetImage1. Setimagebitmap (bitmap);//Set Bitmap}/*** Load Local image *http://bbs.3gstdy.com* @paramurl*@return*/ Public StaticBitmap getloacalbitmap (String url) {Try{FileInputStream fis=Newfileinputstream (URL); returnBitmapfactory.decodestream (FIS); } Catch(FileNotFoundException e) {e.printstacktrace (); return NULL; }}/*** Take pictures from the server *http://bbs.3gstdy.com* @paramurl*@return*/ Public StaticBitmap gethttpbitmap (String url) {URL myfileurl=NULL; Bitmap Bitmap=NULL; Try{log.d (TAG, URL); Myfileurl=Newurl (URL); } Catch(malformedurlexception e) {e.printstacktrace (); } Try{HttpURLConnection conn=(HttpURLConnection) myfileurl.openconnection (); Conn.setconnecttimeout (0); Conn.setdoinput (true); Conn.connect (); InputStream is=Conn.getinputstream (); Bitmap=Bitmapfactory.decodestream (IS); Is.close (); } Catch(IOException e) {e.printstacktrace (); } returnbitmap;}
View Code
Android uses ImageView to display local and online images