如何从 Windows Store 应用程序中的视频中获取缩略图? [英] How to get thumbnail from a video in Windows Store app?

查看:24
本文介绍了如何从 Windows Store 应用程序中的视频中获取缩略图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一款具有录制视频功能的应用.我知道如何录制视频并将其保存在应用程序的 localFolder 中.我的问题是我需要在用户录制视频后向他显示缩略图.因此,为此我想从录制的视频中提取第一帧.最终视频存储在 StorageFile 对象中,但我不知道如何从 StorageFile 对象获取图像.

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.

请任何人都可以建议一些示例代码我该怎么做.我正在使用默认的 Camera API 来录制视频.我的代码在下面

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);
    }
}

这里的saveVideoandShowThumbnail()方法是将视频保存在Videos文件夹中并生成缩略图.

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

推荐答案

StorageFile.GetThumbnailAsync() 解决了我的问题.我尝试使用以下代码显示视频中的图像.希望对某人有帮助

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));

这篇关于如何从 Windows Store 应用程序中的视频中获取缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆