문제

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?

도움이 되었습니까?

해결책

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)

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top