扫描本地图片缩略图的方法
2014-10-14 10:53
183 查看
最近整理了一下项目中使用的保存本地图片缩略图和视频缩略图的方法:
/* 得到本地的压缩图片
*
* @param imagePath
* @param width
* @param height
* @return
*/
private Bitmap getImageThumbnail(String imagePath, int width, int height) {
Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// 获取这个图片的宽和高,注意此处的bitmap为null
bitmap = BitmapFactory.decodeFile(imagePath, options);
options.inJustDecodeBounds = false; // 设为 false
// 计算缩放比
int h = options.outHeight;
int w = options.outWidth;
int beWidth = w / width;
int beHeight = h / height;
int be = 1;
if (beWidth < beHeight) {
be = beWidth;
} else {
be = beHeight;
}
if (be <= 0) {
be = 1;
}
options.inSampleSize = be;
// 重新读入图片,读取缩放后的bitmap,注意这次要把options.inJustDecodeBounds 设为 false
bitmap = BitmapFactory.decodeFile(imagePath, options);
// 利用ThumbnailUtils来创建缩略图,这里要指定要缩放哪个Bitmap对象
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
/* 得到本地的压缩图片
*
* @param imagePath
* @param width
* @param height
* @return
*/
private Bitmap getImageThumbnail(String imagePath, int width, int height) {
Bitmap bitmap = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
// 获取这个图片的宽和高,注意此处的bitmap为null
bitmap = BitmapFactory.decodeFile(imagePath, options);
options.inJustDecodeBounds = false; // 设为 false
// 计算缩放比
int h = options.outHeight;
int w = options.outWidth;
int beWidth = w / width;
int beHeight = h / height;
int be = 1;
if (beWidth < beHeight) {
be = beWidth;
} else {
be = beHeight;
}
if (be <= 0) {
be = 1;
}
options.inSampleSize = be;
// 重新读入图片,读取缩放后的bitmap,注意这次要把options.inJustDecodeBounds 设为 false
bitmap = BitmapFactory.decodeFile(imagePath, options);
// 利用ThumbnailUtils来创建缩略图,这里要指定要缩放哪个Bitmap对象
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
private Bitmap getVideoThumbnail(String videoPath, int width, int height, int kind) { Bitmap bitmap = null; // 获取视频的缩略图 bitmap = ThumbnailUtils.createVideoThumbnail(videoPath, kind); System.out.println("w" + bitmap.getWidth()); System.out.println("h" + bitmap.getHeight()); bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bitmap; }
相关文章推荐
- 获取本地视频缩略图,既第一帧图片的方法
- 获取本地图片缩略图的方法
- 上传图片并显示缩略图的最简单方法(c#)
- ASPX保存远程图片到本地的两种方法的函数
- asp 图片正则 替换,替换前检查图片是不是本地地址的方法
- 扫描图片按原图尺寸打印的方法
- 没有ID的验证码图片,调用方法将图片保存到本地
- ASPX保存远程图片到本地的两种方法的函数
- jsp获取远程图片保存到本地服务器上方法
- .net生成图片的缩略图的2种方法
- 点击图片下载到本地的方法总结(ASP)
- 在 CSDN论坛 不用链接发本地图片方法
- 上传图片并显示缩略图的最简单方法(c#)
- .net生成图片的缩略图的2种方法
- 保存远程图片到本地 同时取得第一张图片并创建缩略图
- 图片上传即时显示缩略图的方法(转)
- 上传图片并显示缩略图的最简单方法(c#)
- ASP保存远程图片到本地 同时取得第一张图片并创建缩略图
- ASPX保存远程图片到本地的两种方法的函数
- asp 图片正则 替换,替换前检查图片是不是本地地址的方法