Out of Memory when loading a photo

Discussion in 'Questions (Windows Mobile)' started by Mr_Gee, Oct 22, 2008.

  1. Mr_Gee

    Mr_Gee Active Member Licensed User

    Hi all,

    I was looking for a small quick image viewer, one that can be linked to image files (open on double click)
    I couldn't find anything I liked so I tried something myself

    I have 2 files 1 landscape and 1 portrait.

    This is the sub, but when I call it the ide (on the ppc) gives me an Out Of Memory error, this only happens with an image file of 737KB the 593KB file loads as it should...

    Sub ProcessImage(Image)
    Image = "L.jpg"
    If Img.Width > Img.Height Then 
    Else If Img.Width < Img.Height Then    
    End If 
    Control("Image").Image = Img.Value
    Control("Image").Mode = cStretchImage 

    End Sub
    Is there a better way to accomplish this, or is there a memory estriction on B4P ...
    Am i missing something

    in other words

  2. agraham

    agraham Expert Licensed User

    That 737K jpg is going to expand to about 10 megabytes of bitmap data or more, the exact amount depending upon how compressed it is so you may well be genuinely running out of memory on the device!
  3. Mr_Gee

    Mr_Gee Active Member Licensed User

    So B4P is decompressing the jpg into a bmp...
    kinda like a temp file...

    How would I go about fixing this ?
    there are picture viewers out there which are create using .net
    so it must be possible...
  4. agraham

    agraham Expert Licensed User

    If you want to display pictures that big your only option is to free up memory.

    It is not a .NET thing, run the program on yout PC and it will be fine. It is a shortage of memory - big pictures need lots of memory. I'm afraid its governed by the laws of nature.
  5. Mr_Gee

    Mr_Gee Active Member Licensed User

    Isn't there a way around this?
    I mean, there are plenty applications that display pictures, and that don't have this issue
    B4P creates a bmp file, but isn't there any way that it uses the existing jpg file?
    this should also help loading times (since it doesn't need to decompress)
  6. agraham

    agraham Expert Licensed User

    Please don't take offence but I think we have a lack of understanding of what's going on here.

    The way that an image is represented for manipulation or display is as a bitmap where each pixel is represented by one or more bytes of data. Devices running .NET 2.0 can support bitmaps using 2, 3 or 4 bytes per pixel. For 2 bytes per pixel 5 bits are used to represent each colour with green possibly using the sixth bit. 3 bytes per pixel give red, green and blue values of 8 bits each and 4 bytes adds a transparency value as the fourth byte. All images, no matter what their storage format, must be decoded into one of these formats before display. The default on the device, according to the Microsofts docs though I haven't confirmed this myself, is 4 bytes per pixel and the default is what ImageLib (and ImageLibEx) uses.

    The picture data from a bitmap can be stored in a file in one of several formats that compress the bitmap data, either reversibly or in a lossy manner. However in all cases the data must be decompressed before use. You cannot use jpg file data as it stands - it must be decoded into a bitmap. If you start at "Bitmap" in Wikipedia there are links to the file storage formats you can explore.
  7. Mr_Gee

    Mr_Gee Active Member Licensed User

    No I don't feel offended, I'm happy someone know what he is talking about
    B4P is a great tool, and I can get things done, but there is still soo much more to learn

    I'm glad you are not offended by some of my n00b questions :)
    so thanks again
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice