编程语言
首页 > 编程语言> > java – 如何使用Universal ImageLoader加载图像而不显示

java – 如何使用Universal ImageLoader加载图像而不显示

作者:互联网

我正在尝试做这样的事情:
Android Map api v2 Custom marker with ImageView
但我坚持使用图像加载器.

试:

Bitmap bmImg = imageLoader.loadImageSync(url);

LogCat给了我

 04-13 14:11:44.953: E/ImageLoader(18542): android.os.NetworkOnMainThreadException

这是我的代码.我有一个ArrayList相机,需要所有信息(titrle,position,url等).

public void drawPicsOnMap()
{                       
    String title = null;
    String place = null;        
    for (int i = 0; i<camera.size(); i++)
    {
        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap bmp = Bitmap.createBitmap(80, 80, conf);
        Canvas canvas = new Canvas(bmp);

        // paint defines the text color,
        // stroke width, size
        Paint color = new Paint();
        color.setTextSize(35);
        color.setColor(Color.BLACK);

        Camera cam = camera.get(i);
        LatLng coord = new LatLng(cam.lat, cam.lon);

        title = Integer.toString(cam.id);
        place = cam.place;                                  

        String url = cam.img;
        Bitmap bmImg = imageLoader.loadImageSync(url);

        //modify canvas
        canvas.drawBitmap(bmImg, 0,0, color);
        canvas.drawText(title, 30, 40, color);

        Marker mark = map.addMarker(new MarkerOptions()
        .position(coord)
        .title(title)
        .snippet(place)
        .icon(BitmapDescriptorFactory
                .fromBitmap(bmp)));

        markers.put(mark.getId(), url);
    }
}

解决方法:

试试这个:

imageLoader.loadImage(url, new SimpleImageLoadingListener(){

                    @Override
                    public void onl oadingComplete(String imageUri, View view,
                            Bitmap loadedImage) {
                    super.onLoadingComplete(imageUri, view, loadedImage);

                        //write your code here to use loadedImage
                    }

                });

这里
onLoadingComplete将在UI线程上调用,这使得线程安全

标签:google-maps-api-2,android,java,universal-image-loader
来源: https://codeday.me/bug/20190825/1715896.html