Camera/imageview problem

Jack Cole

Well-Known Member
Licensed User
Longtime User
I've been struggling with a problem related to images taken using the camera library with loading them into an imageview. I have attached example code.

What happens is that you can load 1 or 2 images into an imageview taken with the camera, but any more than that and the app forces close.

To reproduce the behavior with the example, tilt your phone so it re-orients to landscape mode. Then snap a picture. What this example does is loads the pic into an imageview to the side of the view finder panel. On my droid X2, it will only load 1 pic. On my milestone, it will load 2 images and then force close.

Note: this is not the original app that I am having the problems with, but a stripped down version of the advanced camera example where I reproduced the problem.

I thought it might be a memory problem with the size of the images being loaded into the imageview, so I attempted to use the JPEG library and load a thumbnail. However, that just returns a format error and won't load the image. Any help would be greatly appreciated.

Thanks,
Jack
 

Attachments

  • camtest.zip
    6.9 KB · Views: 198

Jack Cole

Well-Known Member
Licensed User
Longtime User
The Droid X2 has a dual core 1 ghz processor, 512kb ram, 8 mp camera, 4.3" screen. It has android 2.3.4. I tried killing any extraneous processes and turned off the task killer as well, and it still crashes every time I take the second pic.

I have an older phone that I also use for testing (Motorola Milestone), and it crashes after the second pic. It is interesting that it works fine on your tablet.

The error message is, 'the application has stopped unexpectedly. Please try again.'
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
I was able to verify that this is related to a memory problem looking at the unfiltered log. The question is, how to load a camera image without running out of memory.

Log attached.
 

Attachments

  • screenshot.jpg
    screenshot.jpg
    31 KB · Views: 190
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
vb1992, that solved the problem! Thanks much. I've been struggling with this for quite awhile and wasn't aware of loadbitmapsample.

Also, thanks to njdude for the reference to the other forum. That helped me narrow down the problem.

Jack
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
Hey,

I know this is a pretty old thread, but I'd like to know if this completely solved your problem.

I'm trying to achieve the same thing with my app. From studying the log I can see that bitmapsample uses less memory than loading the entire image, however the memory still gets stacked up.

The user has the option of taking an infinite number of photos. In the app, I only ever display a single photo at once, which is when they have the option to discard it. I'm not sure why Android isn't destroying the image when the user takes a new one. The memory is stacking up and after 10-15 images I get the outofmemory crash.

Any suggestions?
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Yes, that solved the problem. Just want to make sure you load the sample small enough. If I am loading to an imageview that is 100dip x 100dip, that is the size of the sample I will load. I have an app where I load 135 images into a listview where the images are scaled to 80dip x 80dip.
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
The bitmap sample was doing its job, I could see that in the log. My problem is that android isn't ditching these images once they've been used. I posted here because after reading your solution I expected you to run into the same issue...guess not though. Don't mean to hijack the thread, but can you see why my memory is stacking up from this code?

B4X:
Dim input As InputStream
Dim capturedimage As Bitmap
input.InitializeFromBytesArray(Data, 0, Data.Length)
capturedimage.Initialize2(input)
pnlCameraImage.SetBackgroundImage(capturedimage)
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
It looks like in your code you are loading the full data from the camera into a panel. What I do is save the data to a jpg file then use loadbitmapsample to load a resized image into a panel from the jpg file.

If you could post the full project or an example where I could reproduce the problem, I might be able to determine what is going wrong.
 
Upvote 0

Mickster

Active Member
Licensed User
Longtime User
I was using loadbitmapsample prior to this code, but it wasn't solving the issue. This is my loadbitmapsample code:

B4X:
Dim capturedimage As Bitmap
capturedimage.InitializeSample(File.DirRootExternal, "1.jpg", pnlCamera.Width, pnlCamera.Height)
pnlCameraImage.Visible = True
pnlCameraImage.BringToFront
pnlCameraImage.SetBackgroundImage(capturedimage)

The bitmap sample code loads a smaller image, using less memory. However this doesn't prevent the memory from stacking up. An image may take 7mb of ram instead of 11mb (I'm using a tablet), but after taking a few images the numbers still add up and there is still a memory issue. For some reason Android doesn't want to ditch the image.

Thanks for offering help, but I cannot upload the project as it is too large. I think I should take my issue to a new thread.
 
Upvote 0

Jack Cole

Well-Known Member
Licensed User
Longtime User
Ok. The only other thing I can think of is if you are adding pnlcameraimage to the layout in the same sub, you would be adding a new panel each time a picture is taken. This would cause the memory to stack up.
 
Upvote 0
Top