标签:
获取图片缩微图:
public Bitmap getImageThumbnail(String uri, int width, int height){ Bitmap bm = null; //缩略图 BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;//设置为true, 不会返回位图, 但仍会设置字段, 允许查找位图而不分配内存 //获取原图,将uri路径的文件解析成bitmap , bm = BitmapFactory.decodeFile(uri, options); //设置缩略图之后,将inJustdecodeBounds设置为false, 再获取位图,就是获取一个缩略之后的位图 options.inJustDecodeBounds = false; int beWidth = options.outWidth/width; int beHeight = options.outHeight/height; int be = 1; if(beWidth < beHeight){ be = beWidth; }else { be = beHeight; } if(be <= 1){ be = 1; } /** * If set to a value > 1, * requests the decoder to subsample the original image, * returning a smaller image to save memory. */ options.inSampleSize = be; //重新获取bitmap, 这个时候获取的就是缩略图 bm = BitmapFactory.decodeFile(uri, options); //创建一个指定width,height的位图 bm = ThumbnailUtils.extractThumbnail(bm, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bm; }
获取视频缩微图:
//kind MediaStore.Images.Thumbnails.MICRO_KIND
public Bitmap getVideoumbnail(String uri, int width, int height, int kind){ Bitmap bm = null; bm = ThumbnailUtils.createVideoThumbnail(uri, kind); bm = ThumbnailUtils.extractThumbnail(bm, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bm; }
sd
android 自定义的小工具类(1)获取图片和视频的缩微图
标签:
原文地址:http://www.cnblogs.com/chengbao/p/5631752.html