Android : Android: Take photo without preview: java.lang.RuntimeException: takePicture failed

on Tuesday, September 30, 2014


I get a java.lang.RuntimeException: takePicture failed for the following Android code:



public class TakePicture {
Camera camera;
Parameters parameters;
Context context;
public TakePicture(Context context)
{
camera = Camera.open();
this.context=context;
parameters = camera.getParameters();
parameters.setPictureFormat(PixelFormat.JPEG);
camera.setParameters(parameters);

SurfaceView sview = new SurfaceView(context);
try {
camera.setPreviewDisplay(sview.getHolder());
camera.startPreview();
camera.takePicture(null,null,photoCallback);
} catch (IOException e) {
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}


}

PictureCallback photoCallback=new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
//...
}
};


}


I simply wanted to take a photo with the front camera without a preview and save it afterwords.


An instance of this class is created in the Main Activity with this code:



TakePicture tp = new TakePicture(this);


Do you have any suggestions how to solve this?


Thanks in advance!


0 comments:

Post a Comment