直接上代码
Bitmap preview = null;
preview = XPopupUtils.getBitmap(resource, XPopupUtils.getAppWidth(context), XPopupUtils.getScreenHeight(context));
if (preview == null) {
// 为null 一般是视频
try {
MediaMetadataRetriever media = new MediaMetadataRetriever();
media.setDataSource(resource.getAbsolutePath());
preview = media.getFrameAtTime();
// 再判下是否为null
if (preview != null){
bigImageView.setImage(ImageSource.cachedBitmap(preview));
}
media.release();
} catch (Exception e) {
e.printStackTrace();
}
} else {
bigImageView.setImage(ImageSource.uri(Uri.fromFile(resource)).dimensions(size[0], size[1]),
ImageSource.cachedBitmap(preview));
}
记得加try catch
网友评论