如何在android中显示从URI下载并显示Bitamp图像?

如何在android中显示从URI下载并显示Bitamp图像?,android,google-maps,bitmap,Android,Google Maps,Bitmap,我刚刚写了这段代码: public class MyActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); String latEiffelTower = "48.858235"; Strin

我刚刚写了这段代码:

public class MyActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_my);
    String latEiffelTower = "48.858235";
    String lngEiffelTower = "2.294571";
    String url = "http://maps.google.com/maps/api/staticmap?center=" + latEiffelTower +   "," + lngEiffelTower + "&zoom=15&size=200x200&sensor=false";
    try {
        ImageView i = (ImageView)findViewById(R.id.image);
        Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(url).getContent());
        i.setImageBitmap(bitmap);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
然后我想从google static map和imageview上的sen下载一个静态图像位图,但我的程序在运行时停止了,如何在代码中显示这个位图图像?我是否使用了任何特殊权限或其他任何东西

这是我的main.xml

 RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 android:paddingBottom="@dimen/activity_vertical_margin"
 tools:context=".MyActivity">

 <TextView
    android:text="@string/hello_world"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
 <ImageView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/image"/>

 </RelativeLayout>
RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android"
xmlns:tools=”http://schemas.android.com/tools"
android:layout\u width=“匹配父项”
android:layout\u height=“match\u parent”
android:paddingLeft=“@dimen/activity\u水平\u边距”
android:paddingRight=“@dimen/activity\u水平\u边距”
android:paddingTop=“@dimen/activity\u vertical\u margin”
android:paddingBottom=“@dimen/activity\u vertical\u margin”
工具:context=“.MyActivity”>

使用通用图像加载模块。可在以下网址找到:

使用它

WebImageLoader imageLoader = new WebImageLoader(context);
ImageView imgProductImage = (ImageView) findViewById(R.id.imgProductImage);
imageLoader.displayImage(imgProductImage,url);
谢谢,
Noorul

我建议使用,您的程序会停止,因为您无法在android主线程上运行网络代码,因为它是为UI任务保留的

您可以简单地使用毕加索下载图像,即:

String latEiffelTower = "48.858235";
String lngEiffelTower = "2.294571";
String url = "http://maps.google.com/maps/api/staticmap?center=" + latEiffelTower +   "," + lngEiffelTower + "&zoom=15&size=200x200&sensor=false";
ImageView i = (ImageView)findViewById(R.id.image);

Picasso.with(MainActivity.this).load(url).into(i);
欲了解更多信息,请访问

String latEiffelTower = "48.858235";
String lngEiffelTower = "2.294571";
String url = "http://maps.google.com/maps/api/staticmap?center=" + latEiffelTower +   "," + lngEiffelTower + "&zoom=15&size=200x200&sensor=false";
ImageView i = (ImageView)findViewById(R.id.image);

Picasso.with(MainActivity.this).load(url).into(i);