我想从我的画廊中选择一段视频。它运行良好。但是现在我想以缩略图的形式显示一个位图。我试过这个代码,但它不起作用,它总是说:NullPointerException
Bitmap bitmap2 = ThumbnailUtils.createVideoThumbnail(uri.getPath, MediaStore.Video.Thumbnails.MICRO_KIND);
这一切都在一个onActivityResult()
中。
如何从视频Uri中获取位图??
谢谢你的帮忙
发布于 2018-10-16 16:48:36
在最新的API24中,如果你坚持接受答案中的方法,你可能会面临一些问题。
例如,在int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
这一行中,有时我会收到W/System.err: java.lang.IllegalArgumentException: column '_data' does not exist
错误消息。
此外,在最新的应用程序接口中,如果您处理小部件或共享内容,则可能会获得SecurityException。请记住这一点。
对于Uri -I中的视频缩略图,使用了一种利用MediaMetadataRetriever的方法,因此您不需要获取字符串filePath:
MediaMetadataRetriever mMMR = new MediaMetadataRetriever();
mMMR.setDataSource(context, videoUri);
bmp = mMMR.getFrameAtTime();
希望这能有所帮助
发布于 2017-05-22 17:31:00
试试这个:
Bitmap bitmap2 = ThumbnailUtils.createVideoThumbnail( uri.getPath() , MediaStore.Images.Thumbnails.MINI_KIND );
发布于 2020-02-14 23:48:30
对于API 27,对于文档URI (1000微秒)
MediaMetadataRetriever mmr = new MediaMetadataRetriever();
mmr.setDataSource( context, doc_uri );
Bitmap bm = mmr.getScaledFrameAtTime( 1000, MediaMetadataRetriever.OPTION_NEXT_SYNC, 128, 128 );
https://stackoverflow.com/questions/44109057
复制相似问题