×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Loading an image in OnNavigatedTo method!!

    In my app, I use a "CreatePage" to create a foreground image and store it in isoloated storage and pass the file path to another page for further editing. Below is the code on how I load the foreground image in OnNavigatedTo method of next page..

    My issue: The foreground image is not loading after I navigated to the page but it is loading after I load a background image with PhotoChoserTask in the same page..

    Whats happening? I even waited for a long time after navigated to the 2nd page.

    IS there anyway to make sure that the image loads immediately after the first visit to the page?

    Code:
            protected override void OnNavigatedTo(NavigationEventArgs e)
            {
                base.OnNavigatedTo(e);
    
                string FilePath = "";
                if (NavigationContext.QueryString.TryGetValue("filePath", out FilePath))
                {
                    GuideTextBlock.Visibility = Visibility.Collapsed;
                    using (var isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                    using (var stream = isoFile.OpenFile(FilePath, FileMode.Open, FileAccess.Read))
                    {
                        var bitmap = new BitmapImage();
                        bitmap.SetSource(stream);
                        FgWriteablebitmap = new WriteableBitmap(bitmap);
                        ForegroundGesture.Input = new BitmapImageSource(FgWriteablebitmap.AsBitmap());
                        stream.Close();
                        bitmap = null;
                    }
                }
            }

  2. #2
    Regular Contributor
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    476

    Re: Loading an image in OnNavigatedTo method!!

    How do you write the jpg stream to the isolate storage?
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  3. #3
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: Loading an image in OnNavigatedTo method!!

    It's png not jpg..

    Here is the code..
    using Cimbalino.Phone.Toolkit

    Code:
    var bmp = new WriteableBitmap(OriginalImage, null);
    
                    string imageFolder = "ClipArts";
                    string imageFileName = "clipr_" + DateTime.Now.ToString().Replace(":", "-") + ".png";
    
                    using (var isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                    {
    
                        if (!isoFile.DirectoryExists(imageFolder))
                        {
                            isoFile.CreateDirectory(imageFolder);
                        }
    
                        filePath = System.IO.Path.Combine(imageFolder, imageFileName);
                        using (var stream = new IsolatedStorageFileStream(filePath, FileMode.Create, isoFile))
                        {
                            bmp.SavePng(stream);
                            stream.Close();
                        }
                    }

  4. #4
    Regular Contributor
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    476

    Re: Loading an image in OnNavigatedTo method!!

    This remember something, but i'm not sure.
    It's something like the file is asynchronously written to the isolatestorage folder. So you try to access it the first time, it's too early.
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  5. #5
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: Loading an image in OnNavigatedTo method!!

    Problem is not with getting the data from isolated storage..I have checked while debugging, writebalebitmap is loading for the first time.

    The problem is at this step,
    Code:
    ForegroundGesture.Input = new BitmapImageSource(FgWriteablebitmap.AsBitmap());
    ForegroundGesture is null and FgWriteablebitmap.AsBitmap() is not null when navigated to the page for first time, where as it is loaded for the second time.

  6. #6
    Regular Contributor
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    476

    Re: Loading an image in OnNavigatedTo method!!

    The first time you enter in OnNavigateTo, ForegroundGesture doesn't know output size. So, it compute scale = 0.
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  7. #7
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: Loading an image in OnNavigatedTo method!!

    What should I do now? Is there any other alternative

  8. #8
    Regular Contributor
    Join Date
    Nov 2011
    Location
    la bouexiere, france
    Posts
    476

    Re: Loading an image in OnNavigatedTo method!!

    Correct ForegroundGesture code to compute scale anly when it have output and input size.
    Windows 8, Windows phone 8 or Nokia Asha developer? Go to DVLUP

  9. #9
    Regular Contributor
    Join Date
    Jan 2014
    Posts
    145

    Re: Loading an image in OnNavigatedTo method!!

    Okay, thank you so much for the help

Similar Threads

  1. WP back button vs OnNavigatedTo method
    By tarhini.hassan in forum Windows Phone General
    Replies: 5
    Last Post: 2011-11-08, 10:46
  2. Replies: 1
    Last Post: 2011-07-18, 08:22
  3. Image rotates if movie clip position changed before image loading
    By supriyaakg in forum [Archived] Flash Lite on Nokia Devices
    Replies: 2
    Last Post: 2010-12-30, 04:27
  4. loading image help..
    By ff123 in forum Symbian
    Replies: 9
    Last Post: 2009-10-14, 17:30
  5. Loading Image
    By jonahkhan1 in forum Symbian Media (Closed)
    Replies: 24
    Last Post: 2008-07-22, 06:22

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×