1

i am a beginner developing a simple Android App where i try to take pictures using the Camera and Camera Preview.

when trying to take the picture i got out of memory errors from 5 and 8 MegaPixel pictures. i therefore tried to use a smaller Camera Preview size.

This works great on my Moto X and my friends Galaxy Note 3 but causes pink and green stripes (ie you cant see the camera preview) on the Galaxy S4 and HTC One.

I have been trying to find a solution (and the only one so far was to not change the camera preview size) but cant find anything.

i come from an iOS background where taking a picture is literally a coding effort of 5 minutes and cant believe it is this complicated on Android.

Anyone have any good third party libraries maybe to have a camera preview and take pictures to work on all phones?

i can post some code too but its 99% the basic code from the android docs.

here is my camera preview class if it helps -http://pastebin.mozilla.org/5698148

Thanks Chris

  • Are you using the MediaRecorder in conjunction with it? http://stackoverflow.com/questions/22390405/how-to-solve-artifact-issue-with-front-camera-video-recording-on-some-android-de – DeeV Jul 29 '14 at 21:54
  • yeah i have the same issue but without the media recorder – Christopher Rivera Jul 30 '14 at 00:59

2 Answers2

0

I recommend you to read this:
Strange out of memory issue while loading an image to a Bitmap

and this: google developer...

Community
  • 1
  • 1
fecub
  • 945
  • 10
  • 27
  • is the main idea of getting an image this: 1. take large image (8MP) 2. save it to file 3. read the file and compress the image before showing it in a imageView? – Christopher Rivera Jul 30 '14 at 00:33
  • i see the same error though as mentioned by deev2 (http://stackoverflow.com/questions/22390405/how-to-solve-artifact-issue-with-front-camera-video-recording-on-some-android-de) – Christopher Rivera Jul 30 '14 at 00:35
  • 1
    @ChristopherRivera For the most part if you're getting a OOM exception before you even save it to the file then there's something else going on. Most commonly people will copy the image in memory without realizing it by using the `BitmapFactory` or `Bitmap` image creation methods. So as you correctly stated, the way around it is save the large image immediately to the file storage. Dump the reference. Then retrieve a compressed version from file whenever you need. – DeeV Jul 30 '14 at 16:32
0

So after a long time I found out that the issue was with

params.setPictureSize(opt.width, opt.height);

for some reason some phones do not like when you call that...

i now just use

params.setPreviewSize(opt.width, opt.height); - which helps against out of memory errors

and then i scale the image before i show it in the ImageView

if anyone needs the code please let me know... ill post it

  • 1
    Welcome to the wonderful world of Android development. Although I haven't experienced this issue. Question, did you check to make sure that your phone supports the resolution that you set it as? There are the `Camera.Parameters#getSupported_____()" methods that tell you what the devices camera can and can't do. In this case, `Camera.Parameters#getSupportedPreviewSize()" is needed to check if the camera preview you set is supported. I'm wondering if setting the preview to something unsupported causes the artifacting. – DeeV Jul 30 '14 at 16:41