Android 显示从Internet下载的图像作为注释-使用毕加索
我无法将从Internet下载的图像显示为批注。我正在实现下面的代码和毕加索库。但是,如果我使用本地图像,它会工作。提前感谢您的帮助Android 显示从Internet下载的图像作为注释-使用毕加索,android,picasso,skmaps,skobbler-maps,Android,Picasso,Skmaps,Skobbler Maps,我无法将从Internet下载的图像显示为批注。我正在实现下面的代码和毕加索库。但是,如果我使用本地图像,它会工作。提前感谢您的帮助 private void createAnnotation(int id, double lat, double lon, String caption, String photoUrl) { SKAnnotation annotation = new SKAnnotation(id); SKCoordinate coordinate = ne
private void createAnnotation(int id, double lat, double lon, String caption, String photoUrl) {
SKAnnotation annotation = new SKAnnotation(id);
SKCoordinate coordinate = new SKCoordinate(lat, lon);
annotation.setLocation(coordinate);
annotation.setMininumZoomLevel(5);
SKAnnotationView annotationView = new SKAnnotationView();
View customView =
(LinearLayout) ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(
R.layout.annotation_photo_and_text, null, false);
// If width and height of the view are not power of 2 the actual size of the image will be the next power of 2 of max(width,height).
//annotationView.setView(findViewById(R.id.customView));
TextView tvCaption = (TextView) customView.findViewById(R.id.annotation_photo_caption);
tvCaption.setText(caption);
ImageView ivPhoto = (ImageView) customView.findViewById(R.id.annotation_photo);
Picasso.with(getApplicationContext())
.load(photoUrl)
.resize(96, 96)
//.centerCrop()
.into(ivPhoto);
//ivPhoto.setImageResource(R.drawable.hurricanerain);
annotationView.setView(customView);
annotation.setAnnotationView(annotationView);
mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE);
}
如果您尝试使用
目标
对象加载图像,然后将下载的位图设置为图像视图
,会怎么样
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
// loading of the bitmap was a success
// TODO do some action with the bitmap
ivPhoto.setImageBitmap(bitmap);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
// loading of the bitmap failed
// TODO do some action/warning/error message
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
}
};
ivPhoto.setTag(target);
Picasso.with(getApplicationContext())
.load(photoUrl)
.resize(96, 96)
.into(target);
毕加索从互联网异步加载图像。下载图像后,尝试将其添加到批注中。您可以使用目标来侦听映像下载完成:
ImageView ivPhoto = (ImageView) customView.findViewById(R.id.annotation_photo);
Target target = new Target() {
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
ivPhoto.setImageBitmap(bitmap);
annotationView.setView(customView);
annotation.setAnnotationView(annotationView);
mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_NONE);
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {}
};
ivPhoto.setTag(target);
Picasso.with(getApplicationContext())
.load(photoUrl)
.resize(96, 96)
.into(target);
尝试使用活动上下文代替applicationcontext。它可能适合您。没有人使用从URL下载的图像进行注释吗?我使用ImageRequest(截取)解决了这个问题。我没有测试你的代码,但它看起来可以工作。非常感谢。