我使用API(...)我收到一個包含png的url,並且我無法顯示圖片。我如何下載並在Android視圖中放置圖像
我必須下載圖片並顯示出來。我把一個手勢要求其他圖片,所以我不得不刪除舊圖片時,當用戶問最新的一個(當他在圖片上做手勢)
所以,我有一種方法,下載並顯示圖片(但屏幕仍黑色...):
private void downloadImage() {
Bitmap bitmap = null;
try {
URL urlImage = new URL("http://www.google.fr/intl/en_com/images/srpr/logo1w.png");
HttpURLConnection connection = (HttpURLConnection) urlImage.openConnection();
InputStream inputStream = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);
Log.v("", "is showed");
image.setImageBitmap(bitmap);
Log.v("", "isn't");
}
catch (MalformedURLException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();}
}
在onload
,我已經把
setContentView(R.layout.secondtab);
圖像=(ImageView的)findViewById(R.id.ivImage);
我在@Override之前聲明瞭ImageView圖像。
在XML中,這就像:
<?xml version="1.0" encoding="utf-8"?>
<android.gesture.GestureOverlayView
android:id="@+id/gestures" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_weight="1.0"
android:eventsInterceptionEnabled="true" android:gestureStrokeType="single"
android:gestureColor="#00FFFFFF"/>
<ImageView
android:id="@+id/ivImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical"
/>
感謝您的幫助:-)
你有什麼試過,你卡在哪裏?從您的描述中很難判斷出您需要哪些幫助:建立與網址的連接?處理結果?一旦你有圖像顯示圖像?別的東西? – 2011-06-14 14:04:11
@泰德:最初的帖子已更新..我想我必須有不同的想法,不是嗎? THAKS – clement 2011-06-14 14:42:18