Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    8

    Image in Isolated Storage as background

    Hi everyone... I'd like to let users to choose a background image... so, this is what i've thought:

    - User select a photo with a photochoser Task
    - the path and the name of the selected photo isa saved in IsolatedStorageSettings
    Code:
    if (e.TaskResult == TaskResult.OK)
                {
                    //Settings.BackgroundPhotoUrl = System.IO.Path.GetFileName(e.OriginalFileName);
                       Settings.BackgroundPhotoUrl = e.OriginalFileName;
                }
    - Everytime the app is launched I read the path/name and show the selected image as background....
    Code:
    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                    {
                        if (!string.IsNullOrEmpty(Settings.BackgroundPhotoUrl))
                        {
                            var fileStream = store.OpenFile(Settings.BackgroundPhotoUrl, FileMode.Open, FileAccess.Read);
                            fileStream.Seek(0, SeekOrigin.Begin);
                            bitmapimage.SetSource(fileStream);
    
                            fileStream.Dispose();
                        }
                    }
    This does not work.. I obtain an exception when i try to open the file: "Operation not permitted on IsolatedStorageFileStream"... Debugging, seems that selected file does not exist!!!! The path is impossible is wrong! But perhaps i need to save the selected image in the Isolated Storage...

    So when I choose a photo I run the following method:

    Code:
    private void SaveToIsolatedStorage(string newPath, Stream choosenPhoto)
            {
                var store =
                    System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication();
    
                if (!store.FileExists(newPath))
                {
                    store.DeleteFile(newPath);
    
                    var stream = store.CreateFile(newPath);
    
                    BitmapImage i = new BitmapImage();
                    i.SetSource(choosenPhoto);
                    WriteableBitmap imageToSave = new WriteableBitmap(i);
                    imageToSave.SaveJpeg(stream,i.PixelWidth, i.PixelHeight, 0, 100);
    
                    stream.Flush();
                    stream.Close();
                }
            }
    Does not work! I obtain the following exception when i try to set the source of the bitmapimage: "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
    "

    Can anyone help me plz?


    Thank you
    Last edited by shinobi86; 2013-12-09 at 00:45.

  2. #2
    Registered User
    Join Date
    Nov 2013
    Posts
    29

    Re: Image in Isolated Storage as background

    this MSDN code sample shows how to load and save images to / from isolated storage

    http://code.msdn.microsoft.com/CSWP8...Stora-8dcf8411

Similar Threads

  1. on device N-97 background image get disappear or get black background
    By amitsharma_ujj in forum [Archived] Qt Mobility Project
    Replies: 13
    Last Post: 2011-05-06, 08:05
  2. problem in display an image button on canvas(Background image)
    By mramin05 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2008-11-12, 05:51
  3. creating a secure and isolated IPC server ?
    By navjotsingh1979 in forum Symbian
    Replies: 11
    Last Post: 2007-05-21, 11:05
  4. Replies: 4
    Last Post: 2006-12-14, 13:33
  5. Problem Isolated. Bug in 6200?
    By johnyin in forum Mobile Java General
    Replies: 2
    Last Post: 2004-03-03, 13:59

Posting Permissions

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