IPhoneThe above implementation is very simple, one lineCode:
Imageview.Image=[UiimageImagewithcontentsofurl:Theurl];
Android:
Two methods:
Bitmap bimage = Getbitmapfromurl (bannerpath); image. setimagebitmap (bimage ); Public Static Bitmap getbitmapfromurl (string SRC ){ Try {Log. E ( "Src" , Src); Url URL = New URL (SRC); httpurlconnection connection = (Httpurlconnection) URL. openconnection (); connection. setdoinput ( True ); Connection. Connect (); inputstream Input = Connection. getinputstream (); bitmap mybitmap =Bitmapfactory. decodestream (input); log. E ( "Bitmap", "returned" ); Return Mybitmap ;} Catch (Ioexception e) {e. printstacktrace (); log. E ( "Exception" , E. getmessage ()); Return Null ;}}
Or try it
Public Static Bitmap loadbitmap (string URL) {Bitmap bitmap = Null ; Inputstream in = Null ; Bufferedoutputstream out = Null ; Try {In = New Bufferedinputstream ( New URL (URL). openstream (), io_buffer_size ); Final Bytearrayoutputstream datastream = New Bytearrayoutputstream (); Out = New Bufferedoutputstream (datastream, io_buffer_size); copy (In, out); Out. Flush (); Final Byte [] DATA = Datastream. tobytearray (); bitmapfactory. Options options = New Bitmapfactory. Options (); // Options. insamplesize = 1; Bitmap = Bitmapfactory. decodebytearray (data, 0 , Data. length, options );} Catch (Ioexception e) {log. E (tag, "Cocould not load bitmap from:" + URL );} Finally {Closestream (in); closestream (out );} Return Bitmap ;}
Method 2
Drawable = Loadimagefromweboperations (bannerpath); image. setimagedrawable (drawable ); Private Drawable loadimagefromweboperations (string URL ){ Try {Inputstream is = (Inputstream) New URL (URL). getcontent (); drawable d = Drawable. createfromstream (is, "src name" ); Return D ;} Catch (Exception e) {system. Out. println ( "Exc =" + E ); Return Null ;}}
Done!