Vb.net 创建WP8应用程序内视频不会生成.jpg缩略图
我被告知,当我允许用户在我的应用程序中创建视频时,应该会自动生成一个.jpg缩略图。但是,使用windows phone power tools,我可以看到只有视频生成,没有图像。代码如下: 编辑:这里的问题是,如何从保存在独立存储中的给定视频中获取缩略图?Vb.net 创建WP8应用程序内视频不会生成.jpg缩略图,vb.net,windows-phone-8,windows-phone,Vb.net,Windows Phone 8,Windows Phone,我被告知,当我允许用户在我的应用程序中创建视频时,应该会自动生成一个.jpg缩略图。但是,使用windows phone power tools,我可以看到只有视频生成,没有图像。代码如下: 编辑:这里的问题是,如何从保存在独立存储中的给定视频中获取缩略图? ' Set recording state: start recording. Private Async Sub StartVideoRecording() Try App.ViewModel.Is
' 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
在Windows Phone 7.0中,除了使用“官方”SDK之外,无法使用“官方”SDK访问摄像头。但是使用
Microsoft.Phone.InteropServices
library可以在应用程序中创建自定义相机视图。如果您使用这个摄像机
类,它会有一个名为ThumbnailSavedToDisk
的事件,这可能就是您所听说的。但Windows Phone Marketplace中绝不允许使用Microsoft.Phone.InteropServices
的应用程序。你可以读更多
要从视频文件生成缩略图,一个解决方案是读取MP4文件格式的工作原理,提取其中一个帧并将其用作缩略图。不幸的是,我还没有找到任何可以这样做的库 另一种远不是最佳解决方案的方法是在MediaElement中播放视频,然后将该控件渲染为位图。这可以通过以下代码实现(用XAML/C#编写,我不知道VB.net,但应该很容易移植):
然后创建缩略图:
// 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();
}
然后创建“捕获”缩略图的事件处理程序:
// 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();
}
下面是使用的修改版本时的外观。(右上角带有蓝色边框的小图像是录制视频的缩略图。后面是摄像头查看器。)
也许你应该坚持官方文件中的信息,而不是来自互联网的谣言?这非常有建设性,非常有用,谢谢。这个网站上有很多人告诉我这件事。如果这个网站上的信息是无关的,没有帮助的-就像你讽刺的语气暗示的那样-那么你为什么在这里?所以,我想windows phone没有办法从保存的视频流制作缩略图?因此,当列出一组视频时,无法直观地表示每个视频…您的问题是什么?你说你听到了一件事,但实际上正在经历另一件事。你能指出应该生成映像的文档吗?显然,以前的windows phone版本中曾经生成过映像,因为我从多个开发人员那里听说过。但不管怎样,我要问的是如何从我在应用程序中拍摄的视频中获取缩略图。是否可能?
Microsoft.Phone.interopservice
可供Microsoft批准的合作伙伴使用。但是推荐使用渲染到曲面的方法,不管怎样,都假定应用程序已经在渲染视频。