So I have an IBuffer
object and I want to save its content into the phone Isolated Storage as JPG. I've tried the following but it gives me error NullReferenceException
.
I suspect the stream was not created properly but how to make it work with 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);
}
}
Error message
{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()}