我对 GifRenderer 类有疑问。在 Windows Phone 8 应用程序中,我的范围是从存储在应用程序隔离存储中的 png 图像列表开始生成动画 gif,然后保存并共享它。当在我的代码中调用 GifRenderer.RenderAsync 方法时,我有一个 ArgumentException,Value 不在预期范围内,正如您在下面的 VB 代码中看到的那样。我在哪里做错了?
Dim images = New List(Of IImageProvider)
Dim image As Picture
Try
For Each fileName In fileNames
images.Add(New StorageFileImageSource(Await StorageFile.GetFileFromPathAsync(IO.Path.Combine(ApplicationData.Current.LocalFolder.Path, fileName))))
Next
Dim info = Await images(0).GetInfoAsync()
Using renderer = New GifRenderer()
renderer.Size = info.ImageSize
renderer.Sources = images
renderer.Duration = 1000
Dim gifBuffer = Await renderer.RenderAsync()
Dim stream = gifBuffer.AsStream()
Using library = New MediaLibrary()
Dim filename = String.Format("{0}+{1}.gif", IO.Path.GetFileNameWithoutExtension(fileNames(0)), fileNames.Count)
image = library.SavePicture(IO.Path.GetFileName(filename), stream)
End Using
End Using
Dim task = New ShareMediaTask()
task.FilePath = image.GetPath()
task.Show()
Catch ex As Exception
Debug.WriteLine(ex)
'renderer.RenderAsync() ->
'System.ArgumentException: Value does not fall within the expected range.
' at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
' at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
' at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
' at WP8.App.VB$StateMachine_0_ShareAnimation.MoveNext()
End Try