2015年9月18日 星期五

[Android] Is it possible to use BitmapFactory.decodeFile method to decode a image from http location? (轉貼)


Is it possible to use BitmapFactory.decodeFile method to decode a image from http location?
ImageView iv = new ImageView(context);
 
try{ 
    String url1 = "http://<my IP>/test/abc.jpg";
    URL ulrn = new URL(url1);
    HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
    InputStream is = con.getInputStream();
    Bitmap bmp = BitmapFactory.decodeStream(is);
    if (null != bmp)
        iv.setImageBitmap(bmp);
    else 
        System.out.println("The Bitmap is NULL");
 
} catch(Exception e) {
} 
Do not forget to disconnect (and hereby release the input stream resource), e.g. finally { if (con != null) { con.disconnect(); } }


http://stackoverflow.com/questions/4509912/is-it-possible-to-use-bitmapfactory-decodefile-method-to-decode-a-image-from-htt

沒有留言:

張貼留言