Out of Memory when loading a photo

Mr_Gee

Active Member
Licensed User
Longtime 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...

B4X:
Sub ProcessImage(Image)
Image = "L.jpg"
   Img.New1(AppPath&"\"&Image)
   If Img.Width > Img.Height Then 
      'Landscape
      AddImage("Form1","Image",20,75,200,150)
   Else If Img.Width < Img.Height Then    
      'Portait
      AddImage("Form1","Image",45,40,150,200)
   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
:sign0085:

Please?
 

Mr_Gee

Active Member
Licensed User
Longtime 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...
 

agraham

Expert
Licensed User
Longtime User
How would I go about fixing this ?
If you want to display pictures that big your only option is to free up memory.


there are picture viewers out there which are create using .net
so it must be possible...
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.
 

Mr_Gee

Active Member
Licensed User
Longtime 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.
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)
 

agraham

Expert
Licensed User
Longtime User
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)
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.
 

Mr_Gee

Active Member
Licensed User
Longtime User
Please don't take offense but I think we have a lack of understanding of what's going on here.

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
 
Top