Question

I have a listview, getting news thumbnail and header from json. I want to show news body and bigger image in other activity by clicking listview item. The code below send image to other activity.

secilenresim= (ImageView)view.findViewById(R.id.mansetresim);                       
secilenresim.buildDrawingCache();
Bitmap image= secilenresim.getDrawingCache();                       
Bundle extras = new Bundle();
extras.putParcelable("imagebitmap", image); 

//// the code below gets the image in new activity

haberresim=(ImageView)findViewById(R.id.haberresim);
haberresim.getLayoutParams().height = 300; 
haberresim.getLayoutParams().width = 400;
Bundle extras = getIntent().getExtras();
Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap");
haberresim.setImageBitmap(bmp);

all works fine. but image quality in new activity is too bad. whereas image source (coming from json and loaded by picasso library) is fine, and the image resolution is 600*400 pixels. How can I pass image to other activity and keep quality?

Was it helpful?

Solution

If you are using picasso, your image is downloaded once and then kept in memory or even disc-cache. So you won't have to pass the bitmap via bundle but only the URL to it from your JSON.

In your Detail-Activity you can request the image via picasso again for your larger imageView.

You can check if your image is loaded from cache or network if you enable the picasso debug flag:

picasso.setDebugging(true)

OTHER TIPS

getDrawingCache() may be getting image with low quality.

to change it use:

secilenresim.setDrawingCacheQuality(DRAWING_CACHE_QUALITY_HIGH);

you can check your quality with getDrawingCacheQuality(). It can be one of those:

  • DRAWING_CACHE_QUALITY_AUTO
  • DRAWING_CACHE_QUALITY_LOW
  • DRAWING_CACHE_QUALITY_HIGH

EDIT:

it seems that secilenresim.destroyDrawingCache(); before building it may be also helpful

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top