如何获取micro_kind等缩略图

时间:2012-05-15 03:42:07

标签: android thumbnails

我的代码如下:

Bitmap getPreview(String path, int THUMBNAIL_SIZE) {
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(path, bounds);
if((bounds.outWidth == -1) || (bounds.outHeight == -1)) {
return null;
}

int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight : bounds.outWidth;

BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = originalSize / THUMBNAIL_SIZE;

return BitmapFactory.decodeFile(path, opts);     
}

但是这段代码只能与原始代码相同。
我想获得96 * 96,例如micro_kind缩略图,但不使用micro_kind 我该如何修改它?

2 个答案:

答案 0 :(得分:1)

您是否尝试过Bitmap#createScaledBitmap

示例:

Bitmap scaled = Bitmap.createScaledBitmap(sourceBitMap, 96, 96, false)

答案 1 :(得分:1)

我通过以下代码得到答案:

Bitmap sourceBitMap =  BitmapFactory.decodeFile(p, opts);     
sourceBitMap = ThumbnailUtils.extractThumbnail(sourceBitMap, 96, 96);