设为首页 加入收藏

TOP

Android缩略图类源代码(一)
2014-11-24 07:56:36 来源: 作者: 【 】 浏览:0
Tags:Android 缩略 源代码

public class ThumbnailUtils {
private static final String TAG = "ThumbnailUtils";


/* Maximum pixels size for created bitmap. */
private static final int MAX_NUM_PIXELS_THUMBNAIL = 512 * 384;
private static final int MAX_NUM_PIXELS_MICRO_THUMBNAIL = 128 * 128;
private static final int UNCONSTRAINED = -1;


/* Options used internally. */
private static final int OPTIONS_NONE = 0x0;
private static final int OPTIONS_SCALE_UP = 0x1;


/**
* Constant used to indicate we should recycle the input in
* {@link #extractThumbnail(Bitmap, int, int, int)} unless the output is the input.
*/
public static final int OPTIONS_RECYCLE_INPUT = 0x2;


/**
* Constant used to indicate the dimension of mini thumbnail.
* @hide Only used by media framework and media provider internally.
*/
public static final int TARGET_SIZE_MINI_THUMBNAIL = 320;


/**
* Constant used to indicate the dimension of micro thumbnail.
* @hide Only used by media framework and media provider internally.
*/
public static final int TARGET_SIZE_MICRO_THUMBNAIL = 96;


/**
* This method first examines if the thumbnail embedded in EXIF is bigger than our target
* size. If not, then it'll create a thumbnail from original image. Due to efficiency
* consideration, we want to let MediaThumbRequest avoid calling this method twice for
* both kinds, so it only requests for MICRO_KIND and set saveImage to true.
*
* This method always returns a "square thumbnail" for MICRO_KIND thumbnail.
*
* @param filePath the path of image file
* @param kind could be MINI_KIND or MICRO_KIND
* @return Bitmap
*
* @hide This method is only used by media framework and media provider internally.
*/
public static Bitmap createImageThumbnail(String filePath, int kind) {
boolean wantMini = (kind == Images.Thumbnails.MINI_KIND);
int targetSize = wantMini
TARGET_SIZE_MINI_THUMBNAIL
: TARGET_SIZE_MICRO_THUMBNAIL;
int maxPixels = wantMini
MAX_NUM_PIXELS_THUMBNAIL
: MAX_NUM_PIXELS_MICRO_THUMBNAIL;
SizedThumbnailBitmap sizedThumbnailBitmap = new SizedThumbnailBitmap();
Bitmap bitmap = null;
MediaFileType fileType = MediaFile.getFileType(filePath);
if (fileType != null && fileType.fileType == MediaFile.FILE_TYPE_JPEG) {
createThumbnailFromEXIF(filePath, targetSize, maxPixels, sizedThumbnailBitmap);
bitmap = sizedThumbnailBitmap.mBitmap;
}


if (bitmap == null) {
try {
FileDescriptor fd = new FileInputStream(filePath).getFD();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
options.inJustDecodeBounds = true;
BitmapFactory.decodeFileDescriptor(fd, null, options);
if (options.mCancel || options.outWidth == -1
|| options.outHeight == -1) {
return null;
}
options.inSampleSize = computeSampleSize(
options, targetSize, maxPixels);
options.inJustDecodeBounds = false;


options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bitmap = BitmapF

首页 上一页 1 2 3 4 5 6 下一页 尾页 1/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android SD卡路径问题以及如何获.. 下一篇Linux 驱动mmap操作

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)