所以我有一个IBuffer
对象,我想将其内容保存到手机独立存储中作为JPG。我尝试过以下操作,但它给了我错误NullReferenceException
。
我怀疑流没有正确创建,但如何使其与IBuffer一起使用?
using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fileStream = store.CreateFile(filePath))
{
MemoryStream stream = new MemoryStream();
photo.ImageBuffer.AsStream().CopyTo(stream);
BitmapImage bitmap = new BitmapImage();
WriteableBitmap wb = new WriteableBitmap(bitmap);
//Encode WriteableBitmap object to a JPEG stream.
Extensions.SaveJpeg(wb, fileStream, (int)photo.Dimensions.Width, (int)photo.Dimensions.Height, 0, 100);
}
}
错误消息
{System.NullReferenceException: Object reference not set to an instance of an object.
at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
at MS.Internal.XcpImports.WriteableBitmap_CreateFromSource(WriteableBitmap wb, IntPtr ptrMemory, BitmapSource source, Boolean& bHasProtectedContent)
at System.Windows.Media.Imaging.WriteableBitmap..ctor(BitmapSource source)
at LensBlurX.Helpers.ISOHelper.<SaveJPG>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at LensBlurX.Pages.PhotoPage.<SaveAsync>d__12.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at LensBlurX.Pages.PhotoPage.<save_Click>d__1e.MoveNext()}