根据原图路径获得对应的缩略图

  • Post author:
  • Post category:其他
根据原图路径获得对应的缩略图 这样可以有效的防止内存溢出 和图片加载慢的问题 这个要在2.2以后才有用网上有很多介绍我就不啰嗦了直接上代码

public static Bitmap getBitmap(ContentResolver cr, String fileName) {

Bitmap bitmap = null;

BitmapFactory.Options options = new BitmapFactory.Options();

options.inDither = false;

options.inPreferredConfig = Bitmap.Config.ARGB_8888;

//select condition.

String whereClause = MediaStore.Images.Media.DATA + ” = ‘” + fileName + “‘”;

//colection of results.

Cursor cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,new String[] { MediaStore.Images.Media._ID }, whereClause,null, null);

if (cursor == null || cursor.getCount() == 0) {

if(cursor != null)

cursor.close();

return null;

}

cursor.moveToFirst();

//image id in image table.

String videoId = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID));

cursor.close();

if (videoId == null) {

return null;

}

long videoIdLong = Long.parseLong(videoId);

//via imageid get the bimap type thumbnail in thumbnail table.

bitmap = MediaStore.Images.Thumbnails.getThumbnail(cr, videoIdLong,Images.Thumbnails.MINI_KIND, options);

return bitmap;

}