开发者

Android :loading remote images in application

开发者 https://www.devze.com 2023-04-13 03:06 出处:网络
I needed to load remote images to my application and bind this image to an QuickcontactBadge object. HttpURLConnection is used to download the image data and BitmapFactory is used to produce the bitma

I needed to load remote images to my application and bind this image to an QuickcontactBadge object. HttpURLConnection is used to download the image data and BitmapFactory is used to produce the bitmap which will be used as imageview resources.

But I dont know exactly how yo do this?开发者_C百科 Can anyone help me over this? Thanks


This could help you.

Bitmap bmImg;
void downloadFile(String fileUrl){
      URL myFileUrl =null;          
      try {
           myFileUrl= new URL(fileUrl);
      } catch (MalformedURLException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
      }
      try {
           HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
           conn.setDoInput(true);
           conn.connect();
           InputStream is = conn.getInputStream();

           bmImg = BitmapFactory.decodeStream(is);
           imView.setImageBitmap(bmImg);
      } catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
      }
 }

Source : http://en.androidwiki.com/wiki/Loading_images_from_a_remote_server

See this too

http://ballardhack.wordpress.com/2010/04/05/loading-remote-images-in-a-listview-on-android/

0

精彩评论

暂无评论...
验证码 换一张
取 消