Android 影片截圖

Android針對影片截圖的方式,可使用MediaMetadataRetriever來完成。

1
2
3
4
5
6
7
8
9
10
11
String videoFilePath = "/storage/sdcard0/Shadows_Die_Twice.mp4"

MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(videoFilePath);

Bitmap bitmap = retriever.getFrameAtTime(1000000);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object

ImageView mView = findViewById(R.id.image);
mView.setImageBitmap(bitmap);

執行結果

作者

Nick Lin

發表於

2019-05-10

更新於

2023-01-18

許可協議


評論