我已在我的应用中动态创建了imageview。我试图从URL加载图像。但它不起作用。我尝试了很多方法,我目前使用的代码是
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png").getContent());
img.setImageBitmap(bitmap);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
但是没有加载图片。什么是错误?
答案 0 :(得分:1)
尝试piccaso库:
ImageView imageView = (ImageView) findViewById(R.id.imageView);
//将图片从url下方加载到imageView
Picasso.with(this).load("https://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png").into(imageView);
//更改网址 获得你的主要许可:
<uses-permission android:name="android.permission.INTERNET" />
调整大小:
Picasso.with(getApplicationContext()).load("https://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png").resize(100, 100).into(i1);
答案 1 :(得分:0)
您可以使用通用图片加载器
UIL旨在为图像加载,缓存和显示提供功能强大,灵活且高度可定制的工具。它提供了许多配置选项,并且可以很好地控制图像加载和缓存过程。
// Load image, decode it to Bitmap and display Bitmap in ImageView (or any other view
// which implements ImageAware interface)
imageLoader.displayImage(imageUri, imageView);
参考链接 - https://github.com/nostra13/Android-Universal-Image-Loader
答案 2 :(得分:0)
使用库从网址加载图片
1.滑翔图书馆请参阅:http://coderzpassion.com/android-working-glide-image-loader-library/
2.毕加索图书馆请参阅:http://coderzpassion.com/android-use-picasso-image-loader-library/
3.排球图书馆请参阅此处:http://coderzpassion.com/android-working-volley-library/
答案 3 :(得分:0)
使用Simple AQuery库从Internet上加载图像
// AQuery object
private AQuery aquery;
aquery = new AQuery(context);
ImageView imageView = (ImageView) findViewById(R.id.imageView);
aquery.id(imageView).image("Your image url ",false,false);
Add permission to manifest file
<uses-permission android:name="android.permission.INTERNET" />