繁体   English   中英

未指定大小的 Android ThumbnailUtils.createVideoThumbnail 在 API 级别 29 中已弃用

[英]Android ThumbnailUtils.createVideoThumbnail with no Size specified is deprecated in API level 29

public static Bitmap createVideoThumbnail (String filePath, 
                int kind)

上述方法在API级别 29 中已弃用。

我们现在需要使用它:

public static Bitmap createVideoThumbnail (File file, 
                Size size, 
                CancellationSignal signal)

我的问题是如何将Size设置为我从中创建缩略图的视频File的本机大小

我希望它具有相同的height/width and dimensions

以前,我可以只使用ThumbnailUtils.createVideoThumbnail(file_path, MediaStore.Images.Thumbnails.FULL_SCREEN_KIND)

使用 MediaMetadataRetriever class 获取大小。 大小将等于创建的视频文件的大小。

public static Size getThumbSize(String path) {
    MediaMetadataRetriever dataRetriever = new MediaMetadataRetriever();
    dataRetriever.setDataSource(path);
    String width = 
    dataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH);
    String height = 
    dataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT);
    return new Size(Integer.parseInt(width), Integer.parseInt(height));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM