Rah*_*med 11 android uri image thumbnails
所以我得到了用户从SD卡中选择的图像的Uri图像.而且我想显示该图像的缩略图,因为很明显,图像可能很大并占据整个屏幕.谁知道怎么样?
您可以使用ThumnailUtil类创建缩略图视频和图像
Bitmap resized = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(file.getPath()), width, height);
public static Bitmap createVideoThumbnail (String filePath, int kind)
Run Code Online (Sandbox Code Playgroud)
在API级别8中添加为视频创建视频缩略图.如果视频损坏或不支持格式,则可能返回null.
参数filePath视频文件种类的路径可以是MINI_KIND或MICRO_KIND
这段代码可以完成这项工作:
Bitmap getPreview(URI uri) {
File image = new File(uri);
BitmapFactory.Options bounds = new BitmapFactory.Options();
bounds.inJustDecodeBounds = true;
BitmapFactory.decodeFile(image.getPath(), bounds);
if ((bounds.outWidth == -1) || (bounds.outHeight == -1))
return null;
int originalSize = (bounds.outHeight > bounds.outWidth) ? bounds.outHeight
: bounds.outWidth;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = originalSize / THUMBNAIL_SIZE;
return BitmapFactory.decodeFile(image.getPath(), opts);
}
Run Code Online (Sandbox Code Playgroud)
您可能想要计算最近的2的幂inSampleSize
,因为据说它更快.
归档时间: |
|
查看次数: |
52267 次 |
最近记录: |