我正在从 url 解码图像,并且我有一组不同的 url,我想在 imageview 中显示从 url 解码的位图图像,但只显示来自最后一个 url 的图像。我无法理解这个问题。
String [] imageLocation={"http://wallbase1.org/thumbs/rozne/thumb-499842.jpg","http: //ns3002439.ovh.net/thumbs/rozne/thumb-2493796.jpg","http://ns3002439.ovh.net/thumbs/rozne/thumb-2486664.jpg"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
image_view = (ImageView)findViewById(R.id.imageview);
while(i<2)
{
bitmap=loadImage(imageLocation[i]);
image_view.setImageBitmap(bitmap);
Animation rotate = AnimationUtils.loadAnimation(LoadImageActivity.this, R.anim.rotate);
findViewById(R.id.imageview).startAnimation(rotate);
i++;
}
}
public Bitmap loadImage(String image_location){
URL imageURL = null;
try {
imageURL = new URL(image_location);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection connection= (HttpURLConnection)imageURL.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream inputStream = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);//Convert to bitmap
}
catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
}