【发布时间】:2016-02-03 16:12:38
【问题描述】:
我正在尝试将图像从 url 加载到我的 android ImageView。但它没有为我的网址提供任何图像。但是当我调用另一个示例 url 时,它会在 ImageView 上加载
我的网址为空
https://192.168.100.15/HeyVoteWeb/Home/GetImage/d9cbd32c-47fc-4644-ab97-1f525c96e9ed/100000102
此示例网址适合我
https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png
这是我正在处理的代码
public class GetImage extends Activity{
ImageView postpic1;
Bitmap b;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.all_posts);
postpic1 = (ImageView) findViewById(R.id.postpic1);
information info = new information();
info.execute("");
}
public class information extends AsyncTask<String, String, String>
{
@Override
protected String doInBackground(String... arg0) {
try
{
URL url = new URL("https://localhost/HeyVoteWeb/Home/GetImage/d9cbd32c-47fc-4644-ab97-1f525c96e9ed/100000102");
InputStream is = new BufferedInputStream(url.openStream());
b = BitmapFactory.decodeStream(is);
} catch(Exception e){}
return null;
}
@Override
protected void onPostExecute(String result) {
postpic1.setImageBitmap(b);
}
}
}
【问题讨论】:
标签: android imageview android-imageview