Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Jan 2014

    Best way to load an image into Memory?

    I want to load an image into memory for editing the same in various pages.

    Which is the best way?


  2. #2
    Nokia Developer Champion
    Join Date
    Mar 2013

    Re: Best way to load an image into Memory?

    It really depends on what exactlly you're trying to do. A stream until read basically is only a means to load data but the data isn't necessarily loaded. The IImageProvider might be reading from the stream or from an already loaded image.

    If you only need a preprocessed image I'd likely build an imaging pipeline using the Imaging SDK and use an IImageProvider that reads directly from Storage. If I repeatedly need to use that image as a basis in processing I'd likely use an Imaging SDK Bitmap to cache the image in memory. I'd only use the standard BitmapImage (part of WP8) if I load an image for display purposes only (so if I don't intend to edit it at all).

    As Render Target for Preview to the user WriteableBitmap is bascially the only option as it can directly be displayed by the Image control. For everything else I'd advise against using WriteableBitmap as memory isn't reclaimed as fast by the GC as it is for the Bitmap upon disposal. If you already did a preview run of a filter in reduced resolution and now want to do a full resolution run to save it you'd use a JpegRenderer which would directly encode the image instead of creating an uncompressed image in memory.

    Basically all the different ways that exist might or might not make sense to use depending on what you actually want to achieve (low memory footprint, speed, etc.). As for the use case you're most likely describing - I'd load the image into memory as an Imaging SDK Bitmap and use that in conjunction with a BitmapImageSource as the source for any Effects I use. I'd then use a WriteableBitmap for Preview of the results or if I'd have to render something to the Image that isn't available through the Imaging SDK (either XAML controls or direct drawing using a library like WriteableBitmapEx).

    It's possible though that others might disagree with my approach. I'd like to hear Yan's take on it as he is very knowledgable about the details of the implementation, etc.

  3. #3
    Regular Contributor
    Join Date
    Oct 2013
    Pennsauken, NJ, USA

    Re: Best way to load an image into Memory?

    The documentation says to wrap a Stream in an IBuffer, so I've been doing this:

    public MemoryStream MemoryStream
                    _originalImage = value;  // this is a Stream
                    _bitmapImage.SetSource(value); //this is a BitmapImage
                    ImageSource = _bitmapImage;  //this is a bindable ImageSource
                    value.Position = 0;
                    iBuffer = value.GetWindowsRuntimeBuffer();  //use this IBuffer to create your sources for Nokia Imaging SDK
                    PreFilter();  //image render before filters are applied
    (You need "using Nokia.InteropServices.WindowsRuntime;" to get the GetWindowsRuntimeBuffer extension.)

    I don't know if that's completely correct, but otherwise I agree with SB Dev.

  4. #4
    Regular Contributor
    Join Date
    Jan 2014

    Re: Best way to load an image into Memory?

    In my App,
    User loads an image from "MediaLibrary" in "ClipPage", then I store it as "IImageProvider" in the same page and close the stream and after user edits the image I use this "IImageprovider" to save the final image into the isostore and dispose everything excepting the file path of saved image.

    After saving the image the app navigates the user to another "MergePage" where I use the file path to load the image as foreground in this page.

    In the "MergePage" user has to select a background image and a foreground image..where if user navigates from a "ClipPage" the foreground image will be automatically loaded (as described above) else ask him's to load the foreground image and I save both of them as Writeablebitmaps in the page for applying blendfilter and saving it in the end.

    I use a "PictureGesture" class to make gestures of both foreground and background image, where is save both these images as IImageProvider into the memory.

    My Issues:

    1. There is a chance of changing the background and foreground images many times so will there be any performance issue?

    2. Am I using the best way to load images into memory?
    Last edited by venu238; 2014-03-13 at 10:28.

Similar Threads

  1. Memory Leak during XML.Load()
    By iderman in forum [Archived] Flash Lite on Nokia Devices
    Replies: 1
    Last Post: 2010-03-02, 19:47
  2. Memory load using emulator
    By fischler in forum Symbian
    Replies: 2
    Last Post: 2009-01-29, 09:40
  3. Can image.createImage load an image not in a jar?
    By nurru in forum Mobile Java General
    Replies: 3
    Last Post: 2007-05-02, 05:19
  4. Where does the class load in Memory and How much Memory Consume
    By sharma_durg in forum Mobile Java General
    Replies: 2
    Last Post: 2006-10-13, 22:34
  5. How do I load a file into memory?
    By aehrath in forum Symbian
    Replies: 3
    Last Post: 2003-07-28, 15:26

Posting Permissions

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