我想通過返回Splat.IBitmap將佈局數據呈現爲與平臺無關的方式的位圖,並且無法輸出結果。我的WPF平臺的代碼如下所示:無法從MemoryStream中加載Splat.IBitmap
MemoryStream stream = new MemoryStream();
try
{
RenderTargetBitmap target = new RenderTargetBitmap(1024, 1024, 300, 300, PixelFormats.Default);
PreviewView preview = new PreviewView(); // this does sizing and placement
target.Render(preview);
previewViewModel.Dispose();
BitmapEncoder encoder = new BmpBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(target));
encoder.Save(stream);
stream.Flush();
IBitmap bitmap = BitmapLoader.Current.Load(stream, 1024, 1024).Result;
stream.Dispose();
return bitmap;
}
catch (Exception e)
{
// TODO: log error
return null;
}
finally
{
stream.Dispose();
}
我把BitmapLoader.Current.Load
call.The內部異常上打一個AggregateException
是與消息No imaging component suitable to complete this operation was found.
一個NotSupportedException
我一直沒能找到任何相關的文件來解釋這意味着什麼。或者我做錯了什麼。作爲一個測試,我已經嘗試將位圖編碼器保存到FileStream
,它工作正常。
編輯
有人指出,這個問題可能是this issue重複。他們肯定是相關的,但在這種情況下,我想知道爲什麼要保存到MemoryStream
無法在FileStream
工作時創建有效的圖像數據。
編輯2
在請求,這裏是我在輸出中看到的情況例外:
Exception thrown: 'System.NotSupportedException' in PresentationCore.dll
Exception thrown: 'System.NotSupportedException' in PresentationCore.dll
Exception thrown: 'System.AggregateException' in mscorlib.dll
的AggregateException
的內NotSupportedException
具有此消息和堆棧跟蹤:
No imaging component suitable to complete this operation was found.
at System.Windows.Media.Imaging.BitmapDecoder.SetupDecoderFromUriOrStream(Uri uri, Stream stream, BitmapCacheOption cacheOption, Guid& clsId, Boolean& isOriginalWritable, Stream& uriStream, UnmanagedMemoryStream& unmanagedMemoryStream, SafeFileHandle& safeFilehandle)
at System.Windows.Media.Imaging.BitmapDecoder.CreateFromUriOrStream(Uri baseUri, Uri uri, Stream stream, BitmapCreateOptions createOptions, BitmapCacheOption cacheOption, RequestCachePolicy uriCachePolicy, Boolean insertInDecoderCache)
at System.Windows.Media.Imaging.BitmapImage.FinalizeCreation()
at System.Windows.Media.Imaging.BitmapImage.EndInit()
at Splat.PlatformBitmapLoader.withInit(BitmapImage source, Action`1 block) in y:\\code\\paulcbetts\\splat\\Splat\\Xaml\\Bitmaps.cs:line 80
at Splat.PlatformBitmapLoader.<>c__DisplayClass2.<Load>b__0() in y:\\code\\paulcbetts\\splat\\Splat\\Xaml\\Bitmaps.cs:line 25
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
即例外NotSupportedException
只有此消息,並沒有堆棧跟蹤:
The component cannot be found. (Exception from HRESULT: 0x88982F50)
的可能的複製[「適合來完成這個操作沒有成像部件被發現」(http://stackoverflow.com/questions/7292764/no-imaging-component-suitable-to-complete-this-operation-was-found) – bradgonesurfing
相關,但不是重複。該問題的根本原因是無法下載圖像並從無效圖像中拋出異常。 這是肯定可能的,我正在做的事情導致我的'MemoryStream'沒有有效的圖像數據,但正如我所說的,它工作正常,如果我使用'FileStream'。如果你能指出我的錯誤,我將不勝感激。 –
爲什麼不設置斷點並查看引發錯誤的位置。 – bradgonesurfing