我用Android-Universal-Image-Loader
制作了gridview并且,当我选择一张图片时,它会进入图像视图。
当我先选择它时,它运行正常。但第二个崩溃了。 (内存不足)
我加载超过1M尺寸的图像(最初是默认相机拍摄的)
这里是初始化的代码
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.memoryCacheExtraOptions(480, 800) // default = device screen dimensions
.discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75)
.taskExecutor(AsyncTask.THREAD_POOL_EXECUTOR)
.taskExecutorForCachedImages(AsyncTask.THREAD_POOL_EXECUTOR)
.threadPoolSize(3) // default
.denyCacheImageMultipleSizesInMemory()
.memoryCacheSize(2 * 1024 * 1024)
.discCacheSize(50 * 1024 * 1024)
.discCacheFileCount(100)
.enableLogging()
.build();
并且在选择时获取uri
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// when clicked image
//startImagePagerActivity(position);
//URI imageUri = URI.parse("android.resource://com.kmob.camera/" + parent.getItemIdAtPosition(position));
SignUp.profilePath = Uri.parse(imageUrls[position].substring(7)); // return selected uri except prefix, "file://"
Log.v("OWL", "selected file: " + imageUrls[position].substring(7));
finish();
}
});
,这是活动的结果
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
//mProfile.notifyAll();
if(profilePath.getPath().toString().length()>0){
mProfile.setImageURI(profilePath);
}
}
提前致谢,
答案 0 :(得分:0)
根据作者的建议,在displayoptions中提到以下两行
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.bitmapConfig(Config.RGB_565) in displayioptions.
在配置中
.memorycache(new WeakMemoryCache())