首页 > 其他 > 详细

bitmap生产缩略图

时间:2021-02-05 19:13:02      阅读:22      评论:0      收藏:0      [点我收藏+]
Android BitMap数据源生产缩略图 
/**
* 生成缩略图
* 缩略图是将原图等比压缩,压缩后宽、高中较小的一个等于198像素
*/
private Bitmap getThumb(Bitmap bm){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bm .compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] bitmapByte = stream.toByteArray();

final BitmapFactory.Options options = new BitmapFactory.Options();
int reqWidth, reqHeight, width = bm.getWidth(), height = bm.getHeight();
if (width > height){
reqWidth = 240;
reqHeight = (reqWidth * height)/width;
}else{
reqHeight = 160;
reqWidth = (width * reqHeight)/height;
}
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
options.inSampleSize = inSampleSize;
options.inJustDecodeBounds = false;
Matrix mat = new Matrix();
Log.d(TAG, "data.length========"+bitmapByte.length);
Bitmap bitmap = BitmapFactory.decodeByteArray(bitmapByte, 0, bitmapByte.length, options);
Log.d(TAG, "klx====bitmap.getWidth()===="+bitmap);
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mat, true);
}

bitmap生产缩略图

原文:https://www.cnblogs.com/Anonyme/p/14378447.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!