9

I am taking photo capture using front camera using my custom camera app not using system camera app.But the captured photo is very dark so can see photo properly.

my code

mCamera = Camera.open(1);
Camera.Parameters params =mCamera.getParameters();
params.setSceneMode(Camera.Parameters.SCENE_MODE_NIGHT);
mCamera.setParameters(params);

And to take picture

if (mCamera != null) {
try {
 mCamera.setPreviewDisplay(mSurfaceHolder);
 mCamera.startPreview();
 mCamera.takePicture(null, mPictureCallback,
 mPictureCallback);
} catch (IOException e) {
 e.printStackTrace();
    }
}

Thanks in advance. Please give me suggestions. any help will be appreciated.

Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
kiran boghra
  • 3,662
  • 2
  • 18
  • 23
  • 1
    Would it not be to do with your use of `SCENE_MODE_NIGHT`? As a photographer, I'd expect night mode to darken photos, basically telling the camera's exposure metering that the overall scene is likely to be a lot darker than a normal photo. What happens if you try `SCENE_MODE_AUTO` instead? – Matt Gibson Dec 16 '13 at 10:52
  • SCENE_MODE_AUTO take dark photo. – kiran boghra Dec 16 '13 at 10:58
  • 1
    Is it dark where you are? Seriously, though, not sure what's going on. There's a [previous question](http://stackoverflow.com/questions/19571378/android-image-taken-by-custom-camera-is-too-dark) asking about this, too. It's surprisingly hard, given the hardware variations of Android, to give a solid answer to this type of question, though. – Matt Gibson Dec 16 '13 at 11:04
  • not too much dark so face can not see. there is enough lights – kiran boghra Dec 16 '13 at 11:15
  • Is the result taken by device native camera app significantly less dark? You can try to look at the logcat of mediaServer - this may help you reverse engineer the tuning they apply. – Alex Cohn Dec 17 '13 at 21:22
  • @Alex cohn Thanks but now the problem solved..... – kiran boghra Dec 18 '13 at 04:35
  • 2
    If you've solved your own problem, you can post your solution as an answer here to help other people. – Matt Gibson Dec 22 '13 at 10:55

3 Answers3

15

To solve this problem you could take the picture after some time. Try this:

new Handler().postDelayed(new Runnable() {
  @Override
  public void run() {
      camera.takePicture(null, null, cameraCallback);
  }
}, 1000);
Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48
  • This worked for me as well. Even when I use the stock camera app, it takes a tiny bit of time before it gets the exposure right. – Sam Dec 06 '14 at 03:14
  • Thanks a lot,Finally it worked for me also after wasting 3 hrs – priyanka Feb 22 '17 at 10:33
5

I have found following solution for this, And that worked for me

Wait for some time i.e. 500 ms before capture image using

mCamera.takePicture(null, mPictureCallback,mPictureCallback);
kiran boghra
  • 3,662
  • 2
  • 18
  • 23
0

All the answers in this thread mention an arbitrary delay where as the root cause of this problem is not addressed.

The camera in an android phone does the autofocus activity after the start of the preview and before capturing the picture. The code snippet in the question mentions call to mCamera.takePicture(null, mPictureCallback,mPictureCallback); right after mCamera.startPreview();.

Taking the picture during the autofocus process gives rise to the exposure issues in the image captured, resulting into dark photos. The delays mentioned in the answers give android the time to complete its autofocus and the image captured is perfect. This might not be the case with every device and an arbitrary number may result into failure on some devices.

My recommendation would be following code snippet -

Camera.AutoFocusCallback autoFocusCallBack = new Camera.AutoFocusCallback();
static autoFocusCallBack(){
    mCamera.takePicture(null, mPictureCallback,
     mPictureCallback);
}
if (mCamera != null) {
   try {
     mCamera.setPreviewDisplay(mSurfaceHolder);
     mCamera.startPreview();
     mCamera.autoFocus(autoFocusCallBack);
    } catch (IOException e) {
       e.printStackTrace();
    }
 }

This flow ensures that the takePicture() is called in the autofocus callback implying autofocus was successful. This will give a proper image with appropriate exposure and brightness.

This will also remove the arbitrary delay.

Read this link for Camera.AutoFocus().

Read this link for Camera.takePicture().

Read this link for Camera.startPreview().

Paritosh
  • 1,111
  • 1
  • 12
  • 29
  • I tried this method and it didn't work for me. I created the AutoFocusCallback and moved the code for takePicture() into it, the verified that everything was being called properly. The photos came out dark and blurry whereas using the method submitted by Alessandro Roaro did work (using a handler to delay the takePicture() call). I really wanted this to work to avoid using a hard delay :-( – Joshua W Sep 08 '16 at 20:32
  • Can you post the code snippet ? This works seamlessly for me. – Paritosh Sep 09 '16 at 05:59
  • You means: Camera.AutoFocusCallback autoFocusCallBack = new Camera.AutoFocusCallback(){ @Override public void onAutoFocus(boolean success, Camera camera) { mCamera.takePicture(null, mPictureCallback, mPictureCallback); } }; – kfir Jun 02 '20 at 09:26