1

Basically I navigate to this page and pass it a name as a parameter, which I then use to retrieve that picture from isolated storage. At the same time I retrieve the "frame" from the assets folder.
When I compile the code no error occurs, but once I get to this part during runtime i get a nullexception for frametest. I have tryed building in a frameImage !=null before to ensure theres a value still getting the error. Both images load correctly into the BitMapImage and I can display them aswell(tested this)

        BitmapImage image = new BitmapImage();
        BitmapImage frameImage = new BitmapImage();

        parameter = string.Empty;

        if (NavigationContext.QueryString.TryGetValue("parameter", out parameter))
        {

            picName = parameter + ".jpg";

            //call function to load image source from isolateStorage
            using (isoStore = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isoStore != null)
                {
                    using (isoStream = new IsolatedStorageFileStream(parameter, FileMode.OpenOrCreate, isoStore))
                    {
                        if (isoStream != null)
                        {
                            image.SetSource(isoStream);
                        }
                    }
                    //close the stream object
                    isoStream.Close();
                }
            }
            //close the storage object
            isoStore.Dispose();

            string path = "/Assets/AppGraphics/UserInterface/frame.png";
            Uri uriR = new Uri(path, UriKind.Relative);
            frameImage = new BitmapImage(uriR);

            //error occurs here
            WriteableBitmap frameTest = new WriteableBitmap(frameImage);
            WriteableBitmap imageTest = new WriteableBitmap(image);

            var photo = imageTest;
            var frame = frameTest;
            var merge = new WriteableBitmap(656, 410);

            merge.Blit(new Rect(0, 0, 656, 410), photo, new Rect(0, 0, photo.PixelWidth, photo.PixelHeight)); //draw the photo first
            merge.Blit(new Rect(0, 0, 656, 410), frame, new Rect(0, 0, frame.PixelWidth, frame.PixelHeight)); //draw the frame

            imgCC.Source = merge;

I dont understand why im getting a nullexception, when the object clearly isn't null. Any help or ideas are appreciated.

stacktrace:

   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 PinAppWindowsPhone.confirmPicture.OnNavigatedTo(NavigationEventArgs e)
   at Microsoft.Phone.Controls.PhoneApplicationPage.InternalOnNavigatedTo(NavigationEventArgs e)
   at Microsoft.Phone.Controls.PhoneApplicationPage.Microsoft.Phone.Controls.IPhoneApplicationPage.InternalOnNavigatedToX(NavigationEventArgs e)
   at System.Windows.Navigation.NavigationService.RaiseNavigated(Object content, Uri uri, NavigationMode mode, Boolean isNavigationInitiator, IPhoneApplicationPage existingContentPage, IPhoneApplicationPage newContentPage)
   at System.Windows.Navigation.NavigationService.CompleteNavigation(DependencyObject content, NavigationMode mode)
   at System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(IAsyncResult result)
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
r wank
  • 352
  • 7
  • 22
  • Please show the stack trace of the exception. I am pretty sure it happens elsewhere. – Daniel Hilgarth Apr 10 '13 at 10:33
  • Wow. A NRE from inside the .NET framework. I consider this a bug. Try to isolate it into a self contained console application and then report it on Microsoft Connect. – Daniel Hilgarth Apr 10 '13 at 10:37
  • You should wait for `frameImage` to finish initializing before creating the `WriteableBitmap` (subscribe to the `ImageOpened` event and put your logic in there) – Kevin Gosse Apr 10 '13 at 11:06
  • if i use the ImageOpened event with my logic in it it throws an error further down the line with another nullexception. I cant seem to get this working with any image from assets, but from isolated storage it seems to work. – r wank Apr 10 '13 at 11:30
  • I just went around the issue by overlaying 2 images in 1 stackpanel and creating a new image from that stackpanel – r wank Apr 10 '13 at 12:02

0 Answers0