我正在使用通用图像加载器将缩略图从资产画廊填充到gridview中,但是图像在向上或向下滚动期间加载缓慢,所以我认为因为图像正在以其当前分辨率加载所以我如何更改图像的分辨率例如我用于createScaledBitmap
缩小位图这是我的代码:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
private List<String> mList;
private int mheight;
private int mwidth;
private InputStream is;
private HomePage homePage;
private ImageLoader imageLoader;
public ImageAdapter(Context context, List<String> list, int height, int width) {
mContext = context;
mList = list;
mheight = height;
mwidth = width;
ImageLoader imageLoader = ImageLoader.getInstance();
this.imageLoader = imageLoader;
}
@Override
public int getCount() {
return mList.size();
}
@Override
public Object getItem(int position) {
return mList.get(position).toString();
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
} else {
imageView = (ImageView) convertView;
}
File cacheDir = new File(Environment.getExternalStorageDirectory(), "UniversalImageLoader/Cache");
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)
.threadPoolSize(5)
.memoryCacheExtraOptions(mwidth/3, mwidth/3)
.threadPriority(Thread.MIN_PRIORITY )
.memoryCache(new UsingFreqLimitedMemoryCache(5000000)) // You can pass your own memory cache implementation
.discCache(new UnlimitedDiscCache(cacheDir)) // You can pass your own disc cache implementation
.build();
imageLoader.init(config);
//
//
//display options
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(R.drawable.loading)
.showImageForEmptyUri(R.drawable.loading)
.cacheInMemory()
.cacheOnDisc()
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.EXACTLY)
.build();
// // Create configuration for ImageLoader
String imString = mList.get(position);
String imageUria = "assets://"+imString;
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new GridView.LayoutParams(mwidth/3, mwidth/3));
imageLoader.displayImage(imageUria, imageView ,options );
return imageView ;
} }