0

有人告诉我,当我允许用户从我的应用程序中创建视频时,应该会自动生成一个 .jpg 缩略图。但是,使用windows phone power tools,我可以看到只生成了视频,没有图像。下面是代码:

编辑:这里的问题是,如何从保存在隔离存储中的给定视频中获取缩略图?

        ' Set recording state: start recording.
Private Async Sub StartVideoRecording()
    Try
        App.ViewModel.IsDataLoaded = False

        'isoStore = Await ApplicationData.Current.LocalFolder.GetFolderAsync("IsolatedStore")
        strVideoName = GenerateVideoName()
        isoFile = Await isoVideoFolder.CreateFileAsync(strVideoName, CreationCollisionOption.ReplaceExisting)
        thisAccessStream = Await isoFile.OpenAsync(FileAccessMode.ReadWrite)
        Await avDevice.StartRecordingToStreamAsync(thisAccessStream)

        'save the name of the video file into the list of video files in isolated storage settings
        Dim videoList As New List(Of InfoViewModel)

        isoSettings = IsolatedStorageSettings.ApplicationSettings
        If isoSettings.Contains("ListOfVideos") Then
            videoList = isoSettings("ListOfVideos")
        Else
            isoSettings.Add("ListOfVideos", videoList)
        End If
        videoList.Add(New InfoViewModel With {.Name = strVideoName, .DateRecorded = Date.Now})
        isoSettings("ListOfVideos") = videoList
        isoSettings.Save()
        isoSettings = Nothing


        ' Set the button states and the message.
        UpdateUI(ButtonState.Recording, "Recording...")
    Catch e As Exception
        ' If recording fails, display an error.
        Me.Dispatcher.BeginInvoke(Sub() txtDebug.Text = "ERROR: " & e.Message.ToString())
    End Try
End Sub
4

1 回答 1

1

在 Windows Phone 7.0 中,除了使用CameraCaptureTask之外,无法使用“官方”SDK 来访问相机。但是使用Microsoft.Phone.InteropServices库可以在应用程序中创建自定义相机视图。如果你使用这个VideoCamera类,它有一个名为 的事件ThumbnailSavedToDisk,这可能是你听说过的。Microsoft.Phone.InteropServices但在 Windows Phone Marketplace 中从未允许使用应用程序。你可以在这里阅读更多关于它的信息


要从视频文件生成缩略图,一种解决方案是阅读 MP4 文件格式的工作原理并提取其中一帧并将其用作缩略图。不幸的是,我还没有找到任何可以做到这一点的库。

另一种但远非最佳解决方案是在 MediaElement 中播放视频,然后将该控件呈现为位图。这可以通过以下代码来完成(用 XAML/C# 编写,我不知道 VB.net,但应该很容易移植):

<MediaElement 
    x:Name="VideoPlayer" 
    Width="640" 
    Height="480"
    AutoPlay="True" 
    RenderTransformOrigin="0.5, 0.5" 
    VerticalAlignment="Center" 
    HorizontalAlignment="Center" 
    Stretch="Fill"
    Canvas.Left="80"/>

然后创建缩略图:

// Set an event handler for when video has loaded
VideoPlayer.MediaOpened += VideoPlayer_MediaOpened;
// Read video from storage
IsolatedStorageFileStream videoFile = new IsolatedStorageFileStream("MyVideo.mp4", FileMode.Open, FileAccess.Read, IsolatedStorageFile.GetUserStoreForApplication());
VideoPlayer.SetSource(videoFile);
// Start playback
VideoPlayer.Play();

然后创建“捕获”缩略图的事件处理程序:

void VideoPlayer_MediaOpened(object sender, RoutedEventArgs e)
{
    Thread.Sleep(100); // Wait for a short time to avoid black frame
    WriteableBitmap wb = new WriteableBitmap(VideoPlayer, new TranslateTransform());
    thumbnailImageHolder.Source = wb; // Setting it to a Image in the XAML code to see it
    VideoPlayer.Stop();
}

以下是使用Video Recorder Sample的修改版本时的外观。(右上角蓝色边框的小图是录制视频的缩略图,后面是camera Viewer。)

在此处输入图像描述

于 2013-03-26T17:32:12.347 回答