加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 检索位于WP8.1中应用程序的本地文件夹中的StorageFile(视

发布时间:2020-12-15 22:04:48 所属栏目:百科 来源:网络整理
导读:我正在尝试将ApplicationFile的缩略图放在应用程序的应用程序包(LocalFolder)中.存储文件是媒体文件,可以是图像(jpg或png)或视频(mp4或wmv).现在,当我尝试使用StorageFile类的GetThumbnailAsync(ThumbnailMode)方法获取缩略图时,我得到了 System.Exception :
我正在尝试将ApplicationFile的缩略图放在应用程序的应用程序包(LocalFolder)中.存储文件是媒体文件,可以是图像(jpg或png)或视频(mp4或wmv).现在,当我尝试使用StorageFile类的GetThumbnailAsync(ThumbnailMode)方法获取缩略图时,我得到了

System.Exception : The component cannot be found.

错误,如果文件是图像或不在应用程序包内的视频,同样的工作正常.这是我正在使用的代码隐藏

StorageFile file;
    private async void BtnGetVideo_Click(object sender,RoutedEventArgs e)
    {
        StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("AssetsTestImgs");
        file = await folder.GetFileAsync("SMTest.mp4");
    }

    private async void BtnGetThumb_Click(object sender,RoutedEventArgs e)
    {
        if (file != null)
        {
            BitmapImage image = new BitmapImage();
            image.SetSource(await file.GetThumbnailAsync(ThumbnailMode.VideosView));
            ImagePreview.Source = image;
        }
    }

这是它的xaml

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button x:Name="BtnGetVideo" Content="Get a Local Video" Click="BtnGetVideo_Click"/>
            <Button x:Name="BtnGetThumb" Content="Get Thumbnails" Click="BtnGetThumb_Click"/>
            <Image x:Name="ImagePreview" Height="200"/>
        </StackPanel>

解决方法

我知道这是一个老问题,但它会帮助任何仍在寻找解决方案的人.

下面是我能够在经过3个小时的奋斗之后成功运行的代码,以及它的工作原理.

using (VideoFrameReader videoFrameReader = new VideoFrameReader(newCreatedVideo))
        {
            await videoFrameReader.OpenMF();
            var image = videoFrameReader.GetFrameAsBitmap(TimeSpan.FromSeconds(0));

            videoFrameReader.Finalize();
        }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读