设置URL图像图像视图 [英] set url image to image view
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/4509912/is-it-possible-to-use-bitmapfactory-de$c$cfile-method-to-de$c$c-a-image-from-htt">Is它可以使用BitmapFactory.de codeFILE的方法去codeA形象从HTTP位置?
我要的图像视图设置URL图像的问题。我尝试以下方法
i have a problem in set url image to image view. i tried below methods
方法1:
Bitmap bimage= getBitmapFromURL(bannerpath);
image.setImageBitmap(bimage);
public static Bitmap getBitmapFromURL(String src) {
try {
Log.e("src",src);
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
Log.e("Bitmap","returned");
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
Log.e("Exception",e.getMessage());
return null;
}
}
方法2:
Drawable drawable = LoadImageFromWebOperations(bannerpath);
image.setImageDrawable(drawable);
private Drawable LoadImageFromWebOperations(String url)
{
try
{
InputStream is = (InputStream) new URL(url).getContent();
Drawable d = Drawable.createFromStream(is, "src name");
return d;
}catch (Exception e) {
System.out.println("Exc="+e);
return null;
}
}
我尝试上述两种方法,但都没有工作。两者都显示DEBUG / Skia的(266):---德codeR->德code返回false。我使用的是有效的演示图像的URL路径。但是这条路是行不通的。所以请告诉我什么是错的,我会做什么
i tried above two methods but are not working . both are showing DEBUG/skia(266): --- decoder->decode returned false . i used demo url image paths that is working. but this path is not working .so please tell me what is the wrong and what i will do
感谢你在前进。
最好的问候。
推荐答案
只是测试你的方法1在我的应用程序,它工作得很好。
Just Tested your "Method 1" in my app and it works just fine.
您可能已经在你的AndroidManifest.xml文件忘了这行:
You might have forgotten this line in your AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />
这篇关于设置URL图像图像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!