URL into a ImageView
我查看了整个 stackoverflow 并没有找到一个解决方案!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | package com.example.sfgsfg; import java.io.InputStream; import java.net.URL; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.impl.client.DefaultHttpClient; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.widget.ImageView; public class MainActivity extends ActionBarActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView img = (ImageView) findViewById(R.id.imageView1); try { URL url = new URL( "http://0.tqn.com/d/webclipart/1/0/5/l/4/floral-icon-5.jpg"); // try this url = //"http://0.tqn.com/d/webclipart/1/0/5/l/4/floral-icon-5.jpg" HttpGet httpRequest = null; httpRequest = new HttpGet(url.toURI()); HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = (HttpResponse) httpclient .execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity b_entity = new BufferedHttpEntity(entity); InputStream input = b_entity.getContent(); Bitmap bitmap = BitmapFactory.decodeStream(input); img.setImageBitmap(bitmap); } catch (Exception ex) { } } } |
这是我最近的尝试,我已经尝试了以下所有方法:
在 ImageView 中显示图像(来自 Url)
Android,在等于 ImageView\\ 的图像的 URL 处制作图像
如何在 Android 中通过 URL 加载 ImageView?
如何从 url 为 imageView 设置图像
Android 应用显示来自 URL
的图像
没有任何作用!而且我需要它而不使用 AsyncTask!请帮忙!
您可以使用以下链接之一:
http://androidexample.com/Download_Images_From_Web_And_Lazy_Load_In_ListView_-_Android_Example/index.php?view=article_discription
我强烈推荐使用这个库
n