Android的图片压缩种ThumbnailUtils

Android的图片压缩类ThumbnailUtils

从Android 2.2开始系统新增了一个缩略图ThumbnailUtils类,位于framework包下的android.media.ThumbnailUtils位置,可以帮助我们从mediaprovider中获取系统中的视频或图片文件的缩略图,该类提供了三种静态方法可以直接调用获取。

 

 

1、extractThumbnail (source, width, height)

 

 

/**
 * 
 * 创建一个指定大小的缩略图
 * @param source 源文件(Bitmap类型)
 * @param width  压缩成的宽度
 * @param height 压缩成的高度
 */
ThumbnailUtils.extractThumbnail(source, width, height);
 

2、extractThumbnail(source, width, height, options):

 

 

/**
 * 创建一个指定大小居中的缩略图
 * 
 * @param source 源文件(Bitmap类型)
 * @param width  输出缩略图的宽度
 * @param height 输出缩略图的高度
 * @param options 如果options定义为OPTIONS_RECYCLE_INPUT,则回收@param source这个资源文件
 * (除非缩略图等于@param source)
 * 
 */
 ThumbnailUtils.extractThumbnail(source, width, height, options);
 

 

3、createVideoThumbnail(filePath, kind):

 

 

/**
 * 创建一张视频的缩略图
 * 如果视频已损坏或者格式不支持可能返回null
 * 
 * @param filePath 视频文件路径  如:/sdcard/android.3gp
 * @param kind kind可以为MINI_KIND或MICRO_KIND
 * 
 */
ThumbnailUtils.createVideoThumbnail(filePath, kind);
 

PS: 此类不向下兼容

 

1 楼 iwlk 2011-09-29  
2.2 版本有点高, 目前开发环境是2.1 Android的图片压缩种ThumbnailUtils