如何加载图像与环球ImageLoader的,不显示 [英] how to load image with Universal ImageLoader without displaying
本文介绍了如何加载图像与环球ImageLoader的,不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做这样的事情: <一href="http://stackoverflow.com/questions/14811579/android-map-api-v2-custom-marker-with-imageview">Android地图API第2版自定义标记与ImageView的 但我卡在使用图像加载器。
尝试:
位图bmImg = imageLoader.loadImageSync(URL);
LogCat中给了我
04-13 14:11:44.953:E / ImageLoader的(18542个):android.os.NetworkOnMainThreadException
下面的是我的code。我有一个ArrayList相机所需的全部信息(titrle,位置,网址等)。
公共无效drawPicsOnMap()
{
字符串标题= NULL;
字符串代替= NULL;
的for(int i = 0; I&LT; camera.size();我++)
{
Bitmap.Config的conf = Bitmap.Config.ARGB_8888;
BMP位= Bitmap.createBitmap(80,80,CONF);
帆布油画=新的Canvas(BMP);
//油漆定义文字的颜色,
//笔划宽度,大小
漆膜颜色=新的油漆();
color.setTextSize(35);
color.setColor(Color.BLACK);
相机凸轮= Camera.get方法(ⅰ);
经纬度坐标=新的经纬度(cam.lat,cam.lon);
标题= Integer.toString(cam.id);
地方= cam.place;
字符串URL = cam.img;
位图bmImg = imageLoader.loadImageSync(URL);
//修改画布
canvas.drawBitmap(bmImg,0,0,彩色);
canvas.drawText(标题,30,40,颜色);
标记标志= map.addMarker(新MarkerOptions()
.position(坐标)
.title伪(标题)
是.snippet(地方)
.icon(BitmapDescriptorFactory
.fromBitmap(BMP)));
markers.put(mark.getId(),URL);
}
}
解决方案
试试这个:
imageLoader.loadImage(URL,新SimpleImageLoadingListener(){
@覆盖
公共无效onLoadingComplete(字符串imageUri,视图中查看,
位图loadedImage){
super.onLoadingComplete(imageUri,查看,loadedImage);
//写你的code这里使用loadedImage
}
});
下面 onLoadingComplete将被称为UI线程,这使得它线程安全的。
I'm trying to do something like this: Android Map api v2 Custom marker with ImageView But I'm stuck on using image loader.
Trying:
Bitmap bmImg = imageLoader.loadImageSync(url);
LogCat gives me
04-13 14:11:44.953: E/ImageLoader(18542): android.os.NetworkOnMainThreadException
Here's is my code. I have an ArrayList camera with all information needed (titrle, position, url, etc).
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);
}
}
解决方案
Try this:
imageLoader.loadImage(url, new SimpleImageLoadingListener(){
@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
//write your code here to use loadedImage
}
});
Here onLoadingComplete will be called on UI thread which makes it thread safe
这篇关于如何加载图像与环球ImageLoader的,不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文