我使用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