How to get thumbnail from a video in Windows Store app?

走远了吗. 提交于 2019-12-12 15:30:32

问题


I am currently working on an app in which there is feature to record video. I am aware about how to record the video and save it in localFolder of app. My problem is that I need to show a thumbnail to user after he records the video. So, for that I want to extract the first frame from the recorded video. The final video is stored in StorageFile object but I am not aware how to get image from StorageFile object.

Please can anyone suggest with some sample code how can I do that. I am using default Camera API for recording video. My code is below

private async void CaptureVideo()
{
    CameraCaptureUI cameraUI = new CameraCaptureUI();
    cameraUI.VideoSettings.Format=CameraCaptureUIVideoFormat.Mp4;
    cameraUI.VideoSettings.MaxDurationInSeconds = 10;
    StorageFile capturedVideo = await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Video);
    string videoName="video_" + GetDateTimestamp() +".mp4";
    if(capturedVideo !=null)
    {
        saveVideoandShowThumbnail(capturedVideo, videoName);
    }
}

Here in saveVideoandShowThumbnail() method is to store the video in Videos Folder and generate the thumbnail.


回答1:


StorageFile.GetThumbnailAsync() solved my issue. I tried to show image from video using below code. Hope it helps someone

bitmap = new BitmapImage();
bitmap.SetSource(await videoFile.GetThumbnailAsync(ThumbnailMode.SingleItem));


来源:https://stackoverflow.com/questions/29667235/how-to-get-thumbnail-from-a-video-in-windows-store-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!