我需要一张图片的缩略图。我只知道存储在SD卡中的图像名称,能有人帮助我吗?
试一试。
final int THUMBSIZE = 64;
Bitmap ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath),
THUMBSIZE, THUMBSIZE);
点击此处 以获取更多详细信息。
imagePath
是什么? - Azim AnsariMediaStore.Images.Thumbnails
,您可以查询并获取两种缩略图:MINI_KIND:512 x 384缩略图和MICRO_KIND:96 x 96缩略图。使用此调用的优点是缩略图由MediaStore缓存,因此如果先前创建了缩略图,则检索速度更快。byte[] imageData = null;
try
{
final int THUMBNAIL_SIZE = 64;
FileInputStream fis = new FileInputStream(fileName);
Bitmap imageBitmap = BitmapFactory.decodeStream(fis);
Float width = new Float(imageBitmap.getWidth());
Float height = new Float(imageBitmap.getHeight());
Float ratio = width/height;
imageBitmap = Bitmap.createScaledBitmap(imageBitmap, (int)(THUMBNAIL_SIZE * ratio), THUMBNAIL_SIZE, false);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
imageData = baos.toByteArray();
}
catch(Exception ex) {
}
import rapid.decoder.BitmapDecoder;
...
Bitmap bitmap = BitmapDecoder.from(getResources(), R.drawable.image)
.scale(width, height)
.useBuiltInDecoder(true)
.decode();
如果你想将比例缩小到50%以下并获得高质量的结果,请不要忘记使用内置解码器。