I'm trying to display an image from a url in a "InfoWindowAdapter"
,I have the following code, but does not show me the image
....
mMap = getMap();
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
...
#Override
public View getInfoContents(Marker marker) {
View v = getActivity().getLayoutInflater().inflate(
R.layout.info_window_layout, null);
String image_url = "http://api.androidhive.info/images/sample.jpg";
new DownloadImageTask(imgEquipo).execute(image_url);
return v;
}
});
call to AsyncTask to get image
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
} }
}
tranks for your help.
It won't work because the view is returned before you get the image, and they are not synchronized.
Take a look at this approach:
I my using google mapV2 and i m downloading image from google place api and want to display in the popup
The trick is to update the InfoWindow after you get the image.
Related
Hi guys i have an problem,
I have a list and I have to view it in a list using the reycleview but when I go to the image via cericare phat and to do this use picasso
#Override
public void onBindViewHolder(ViewHolder viewHolder, final int i) {
this.viewHolder=viewHolder;
if(scheduler.size()>=1){
viewHolder.time.setText(scheduler.get(i).getTime());
viewHolder.data.setText(scheduler.get(i).getData());
viewHolder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
removeItem(i);
}
});
String phat=scheduler.get(i).getImageString();
//result paht: content://com.android.providers.media.documents/document/image%3A445
Picasso.with(c).load(phat).into(viewHolder.img);//does not display the image
viewHolder.img.setOnClickListener(new MyClikListener(i));
viewHolder.time.setOnClickListener(new MyClikListener(i));
viewHolder.data.setOnClickListener(new MyClikListener(i));
viewHolder.card_view_reminder.setOnClickListener(new MyClikListener(i));
}
}
I also tried converting the pat in a URI but nothing.
Making debugging tells me onBitmapFailed
Use the below code:
Picasso.with(c).load(new File(phat)).into(viewHolder.imageView);
Hope this helps.
Try this
new DownloadImage(yourImageView).execute(URL);
create AsyncTask for download image from background process
public class DownloadImage extends AsyncTask<String, Void, Bitmap> {
CircleImageView bmImage;
public DownloadImage(ImageView bmImage) {
this.bmImage = (CircleImageView) bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.d("Error", e.getStackTrace().toString());
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
It will work for all..
i seen this, and made how they say.
my app loads and shows .jpg, but don't show .png. He shows empty screen. (tested on versions 4.1 and 4.2)
if (isOnline()) {
new DownloadImageTask((ImageView) findViewById(R.id.imageViewSA))
.execute(img);
} else {
tv_info.setText("Включите интернет для загрузки");
}
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
you can use universal image loader library instead, so easy to integrate in your code, you can display images from URL to imageView like this
imageLoader.displayImage(url, imageView);
here's a good example of using UIL
and the library
good luck ;)
I am trying to retrieve the Facebook Image from profilepictureview and convert it to bitmap but it gives me a blank profile pic. My main goal is to convert the image view to CircularImageView.
https://github.com/Pkmmte/CircularImageView
The code is set in the onCreate method:
profilePictureView = (ProfilePictureView) findViewById(R.id.image_mainlobby);
profilePictureView.setProfileId(userid);
profilePictureView.setPresetSize(ProfilePictureView.LARGE);
ImageView fbImage = ( ( ImageView)profilePictureView.getChildAt( 0));
Bitmap bitmap = ( ( BitmapDrawable) fbImage.getDrawable()).getBitmap();
ImageView im = (ImageView)findViewById(R.id.fb_profile);
im.setImageBitmap(bitmap);
1)onCreate method:
new DownloadImageTask((CircularImageView) findViewById(R.id.fb_cir))
.execute("https://graph.facebook.com/"+userid+"/picture?type=large");
2) create a new class
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
I have a class that extends AsyncTask to get image from a URL:
public class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
I can load it to every ImageView I want, like that:
new DownloadImageTask(mRecipeImage).execute(ImageURL);
I an getting the image while the app is running (dynamically).
I want to set a Relative Layout's background to the image that I am getting from the web.
any ideas?
Please visit this link:
UniversalImageLoader
may it is help full to you.
It is better if you use an ImageLoader library like picasso, volley for downloading and setting Image.
code snippet for using picasso
Picasso.with(context).load("ur_image_url").into(bmImage);
code snippet for using Volley
String url = "http://i.imgur.com/7spzG.png";
// Retrieves an image specified by the URL, displays it in the UI.
ImageRequest request = new ImageRequest(url,
new Response.Listener() {
#Override
public void onResponse(Bitmap bitmap) {
bmImage.setImageBitmap(bitmap);
}
}, 0, 0, null,
new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
bmImage.setImageResource(R.drawable.image_load_error);
}
});
// Access the RequestQueue through your singleton class.
MySingleton.getInstance(this).addToRequestQueue(request);
I want to take the image from a URL and set is as the background of my RelativeLayout. I use the AsyncTask and try to create a Drawable from BitmapDrawable. But I get a NullPointerException and can't seem to figure out why?
class DownloadBackgroundTask extends AsyncTask<String, Void, Bitmap> {
RelativeLayout bmImage;
View vi;
public DownloadBackgroundTask(RelativeLayout bmImage, View vi) {
this.bmImage = bmImage;
this.vi = vi;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
if (result != null)
{
// null pointer exception here
Drawable d = new BitmapDrawable(vi.getContext().getResources(), result);
bmImage.setBackground(d);
}
else
{
bmImage.setBackgroundResource(R.drawable.logo);
}
}
}
onCreateView():
RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.RelativeLayout1);
new DownloadBackgroundTask(rl, rootView).execute("http://pctechmag.com/wp-content/uploads/2012/10/fifa13_messi.jpg");