1
如何使一個HTTP請求到得到圖像鏈接: http://vec03.maps.yandex.ru/tiles?l=map&v=2.20.0&x=19783&y=10320&z=15 能夠添加到ImageView的的Android如何使一個HTTP請求到得到的圖像鏈接,ImageView的
請幫幫忙,我不是好Web開發。
如何使一個HTTP請求到得到圖像鏈接: http://vec03.maps.yandex.ru/tiles?l=map&v=2.20.0&x=19783&y=10320&z=15 能夠添加到ImageView的的Android如何使一個HTTP請求到得到的圖像鏈接,ImageView的
請幫幫忙,我不是好Web開發。
String imageUrl= "http://vec03.maps.yandex.ru/tiles?l=map&v=2.20.0&x=19783&y=10320&z=15";
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is);
imageView.setImageBitmap(img);
谷歌它,你問之前,你的問題,應避免重複問題
public void setImage()
{
ImageView icon=(ImageView)v.findViewById(R.id.icon);
Drawable image = ImageOperations(getapplicationContext(), "yuour url",
"image.jpg");
icon.setImageDrawable(image);
}
private Drawable ImageOperations(Context ctx, String url,
String saveFilename) {
try {
InputStream is = (InputStream) this.fetch(url);
Drawable d = Drawable.createFromStream(is, "src");
return d;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public Object fetch(String address) throws MalformedURLException,
IOException {
URL url = new URL(address);
Object content = url.getContent();
return content;
}
打開URL連接,並獲取圖像作爲位圖,現在設置位圖作爲ImageView的。看看這個教程,http://android-developers.blogspot.in/2010/07/multithreading-for-performance.html – user370305 2012-08-14 10:17:01
也http://stackoverflow.com/questions/2471935/how-to-load-an- imageview-by-url-in-android和http://stackoverflow.com/questions/6238524/how-to-show-an-image-from-an-url-in-android – user370305 2012-08-14 10:19:02
非常感謝你,它的工作原理! http://android-developers.blogspot.in/2010/07/multithreading-for-performance.html – 2012-08-15 07:28:05