Two methods:
Method One:
Bitmap bimage= Getbitmapfromurl (Bannerpath); Image.setimagebitmap (bimage); Public StaticBitmap Getbitmapfromurl (String src) {Try{LOG.E ("src", SRC); URL url =NewURL (SRC); HttpURLConnection connection = (httpurlconnection) url.openconnection (); Connection.setdoinput (true); Connection.connect (); InputStream input = Connection.getinputstream (); Bitmap Mybitmap = Bitmapfactory.decodestream (input); LOG.E ("Bitmap", "returned");returnMybitmap; }Catch(IOException e) {E.printstacktrace (); LOG.E ("Exception", E.getmessage ());return NULL; } }
Or:
Public StaticBitmap loadbitmap (String url) {Bitmap Bitmap =NULL; InputStream in =NULL; Bufferedoutputstream out =NULL;Try{in =NewBufferedinputstream (NewURL (URL). OpenStream (), io_buffer_size);FinalBytearrayoutputstream DataStream =NewBytearrayoutputstream (); out =NewBufferedoutputstream (DataStream, io_buffer_size); Copy (in, out); Out.flush ();Final byte[] data = Datastream.tobytearray (); Bitmapfactory.options Options =NewBitmapfactory.options ();//options.insamplesize = 1;Bitmap = Bitmapfactory.decodebytearray (data, 0, data.length,options); }Catch(IOException e) {LOG.E (TAG, "Could not load Bitmap from:" + URL); }finally{Closestream (in); Closestream (out); }returnBitmap;}
Method 2
drawable drawable = loadimagefromweboperations (Bannerpath); Image.setimagedrawable (drawable); Private drawable loadimagefromweboperations (String url) { try { new url (URL). GetContent (); drawable D = Drawable.createfromstream (IS, "src name"); return D; } Catch (Exception e) { System.out.println ("exc=" +e); return null; } }
Android: Load ImageView via URL