URL图像将不会设置为ImageView Android
我试图从url加载图像到我的android ImageView。但它没有给我的网址形象。但是当我打电话另一个样本网址加载在ImageView的URL图像将不会设置为ImageView Android
我的URL这给空
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);
}
}
}
你有一个本地网络服务器运行支持HTTPS?因为那是你试图从中加载图像的地方。
另外,如果你已经运行,当你在你的浏览器中调用你想要的URL时,你会得到图像吗?
我认为你的问题是在你的URL中,用你的IP地址替换你的本地主机,希望它能解决你的问题。
您是否尝试过使用Picasso库非常简单而有效:
-
转到您的应用程序目录内的build.gradle并添加到依赖性:
compile 'com.squareup.picasso:picasso:2.5.2'
-
然后用毕加索的lib :
String url = "https://localhost/HeyVoteWeb/Home/GetImage/d9cbd32c-47fc-4644-ab97-1f525c96e9ed/100000102";
Picasso.with(context) //The context of your activity .load(url) .into(postpic1);
当我把我的下面的url它不加载imageview是空的。但对于所有其他图像的URL工作 '的https:// 192.168.100.15/HeyVoteWeb /主页/的getImage/d9cbd32c-47fc-4644-ab97-1f525c96e9ed/100000102' – Naz141
我的图片URL我的工作我的浏览器。当我在浏览器中运行网址 – Naz141
@ Naz141时,图像会自动下载,那么这就是你应该直接使用链接到img的问题,而不是链接下载img,它们是2种不同的链接,带有2种不同的功能 – commonSenseCode
这是URL '的https:// 192.168.100.15/HeyVoteWeb /主页/的getImage/d9cbd32c-47fc-4644-ab97-1f525c96e9ed/100000102' – Naz141
是的,我看到了。这是对本地HTTPS网络服务器的调用,那么你有一个运行?如果没有,这个URL永远不会给你一张图片。这将调用您正在运行此操作的计算机/设备,而不是**网络上的随机图像(仅供说明)。 – LilaQ
yes在您的浏览器中运行该网址 – Naz141