Visualización de una imagen descargada de Internet como anotación – Uso de Picasso

No puedo mostrar la imagen descargada de Internet como anotación. Estoy implementando el siguiente código y la biblioteca de Picasso. Sin embargo, si utilizo una imagen local, funciona. Gracias de antemano por cualquier ayuda.

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); } 

Picasso carga imágenes de Internet asincrónicamente. Intente agregar la imagen a la Anotación después de haberla descargado. Puede utilizar un objetivo para escuchar la finalización de descarga de imágenes:

 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); 

Pruebe el contexto de la actividad en lugar de applicationcontext. Puede funcionar para usted.

¿Qué pasa si intenta cargar la imagen utilizando el objeto de Target y, a continuación, establecer bitmap descargado a su ImageView ?

 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); 
  • No se puede calcular el mensaje de error Skobbler "Ruta"
  • Mapas de Skobbler en Android con pantalla en negro
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.