获取缩略图的几种方式
来源:互联网 发布:青山软件培训 编辑:程序博客网 时间:2024/06/05 05:55
//获取视频格式缩略图
1、通过字符串格式的 Uri
private Bitmap getVideoThumbnail(String uri, int width, int height, int kind) {
Bitmap bitmap = null;
bitmap = ThumbnailUtils.createVideoThumbnail(uri, kind);
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
return bitmap;
}
调用:
getVideoThumbnail(uri, 200,200, MediaStore.Images.Thumbnails.MICRO_KIND);
//获取图片的缩略图
public Bitmap getBitmapByPath(String localImagePath) {
int width = 30;
int addedScaling = 30;
if (TextUtils.isEmpty(localImagePath)) {
return null;
}
Bitmap temBitmap = null;
try {
BitmapFactory.Options outOptions = new BitmapFactory.Options();
// 设置该属性为true,不加载图片到内存,只返回图片的宽高到options中。
outOptions.inJustDecodeBounds = true;
// 加载获取图片的宽高
BitmapFactory.decodeFile(localImagePath, outOptions);
int height = outOptions.outHeight;
if (outOptions.outWidth > width) {
// 根据宽设置缩放比例
outOptions.inSampleSize = outOptions.outWidth / width + 1+ addedScaling;
outOptions.outWidth = width;
// 计算缩放后的高度
height = outOptions.outHeight / outOptions.inSampleSize;
outOptions.outHeight = height;
}
// 重新设置该属性为false,加载图片返回
outOptions.inJustDecodeBounds = false;
temBitmap = BitmapFactory.decodeFile(localImagePath, outOptions);
} catch (Throwable t) {
t.printStackTrace();
}
return temBitmap;
}
- 获取缩略图的几种方式
- 安卓获取图片缩略图的两种方式
- 安卓获取图片缩略图的两种方式
- Spring获取Bean的几种方式
- Spring获取Bean的几种方式
- 获取时间的几种方式
- Spring获取Bean的几种方式
- Spring获取Bean的几种方式
- Spring获取Bean的几种方式
- Jquery 获取对象的几种方式
- 获取客户端IP的几种方式
- Jquery 获取对象的几种方式
- Jquery 获取对象的几种方式
- Jquery 获取对象的几种方式
- 几种获取屏幕大小的方式。
- 获取JVM运行状况的几种方式
- 获取applicationContext的几种方式
- Spring获取Bean的几种方式
- 【C语言基础】-02字符串和格式化输入/输出
- java以json格式向后台服务器接口发送请求
- 排序算法总结
- 802.11协议解析
- NSArrayM stringByTrimmingCharactersInSet
- 获取缩略图的几种方式
- 96. Unique Binary Search Trees
- 当当网高可用架构之道
- error C2664: “MessageBoxA”: 不能将参数 2 从“std::string”转换为“LPCSTR”
- HTML&CSS基础学习笔记1.12-无序列表
- 数据库备份类型
- 一套HTML网站后台信息管理静态网页模版下载
- VFS的索引节点
- App架构经验总结