0

以下のように私のコード:

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);     
}

しかし、このコードは元のコードと同じ比率しか得られません。
micro_kind サムネイルなどの 96*96 を取得したいのですが、micro_kind を使用しません。
どうすれば変更できますか?

4

2 に答える 2

1

以下のコードで答えが得られます。

Bitmap sourceBitMap =  BitmapFactory.decodeFile(p, opts);     
sourceBitMap = ThumbnailUtils.extractThumbnail(sourceBitMap, 96, 96);
于 2012-05-15T05:20:56.680 に答える
1

Bitmap#createScaledBitmapを試しましたか?

例:

Bitmap scaled = Bitmap.createScaledBitmap(sourceBitMap, 96, 96, false)
于 2012-05-15T03:50:33.243 に答える