When i make a photo, after the photo is stored, i want that the camera
preview is still on the screen, but something is going wrong, because
after making a photo the camera preview frozens and i get this error:
Camera Error 100, ICamera died
I checked some stackoverflow questions about this error but none of
them help me, i dont know what i am doing bad.
this is the code of my custom camera view class:
public class CustomCameraView extends SurfaceView
{
static final int FOTO_MODE = 0;
SurfaceHolder previewHolder;
Camera camera;
Context myContext;
boolean mPreviewRunning = false;
public CustomCameraView(Context ctx)
{
super(ctx);
myContext=ctx;
previewHolder = this.getHolder();
previewHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
previewHolder.addCallback(surfaceHolderListener);
this.requestFocus(); //necessary to manage camera button
events
this.setFocusableInTouchMode(true); //necessary to manage
camera button events
}
SurfaceHolder.Callback surfaceHolderListener = new
SurfaceHolder.Callback()
{
public void surfaceCreated(SurfaceHolder holder)
{
camera=Camera.open();
try {
camera.setPreviewDisplay(previewHolder);
}catch (Exception E ){ }
}
public void surfaceChanged(SurfaceHolder holder, int format, int
w, int h) {
if (mPreviewRunning) { //stopPreview() will crash if
preview is
not running
camera.stopPreview();
}
Camera.Parameters p = camera.getParameters();
p.setPreviewSize(w, h);
//p.setPictureSize(1024, 768);
camera.setParameters(p);
try {
camera.setPreviewDisplay(holder);
} catch (IOException e) {e.printStackTrace();}
camera.startPreview();
mPreviewRunning = true;
}
public void surfaceDestroyed(SurfaceHolder holder) {
camera.stopPreview();
mPreviewRunning = false;
camera.setPreviewCallback(null);
camera.release();
camera=null;
}
};
Camera.PictureCallback mPictureCallback = new
Camera.PictureCallback() {
public void onPictureTaken(byte[] imageData, Camera c) {
if (imageData != null) {
StoreByteImage(myContext, imageData, 50,
"ImageName");
camera.startPreview();
}
}
};
public static boolean StoreByteImage(Context mContext, byte[]
imageData, int quality, String expName) {
File sdImageMainDirectory = new File("/sdcard");
FileOutputStream fileOutputStream = null;
//String nameFile;
try{
BitmapFactory.Options options=new
BitmapFactory.Options();
options.inSampleSize = 1;//reduce el tamaƱo de la foto
Bitmap myImage =
BitmapFactory.decodeByteArray(imageData, 0,
imageData.length,options);
fileOutputStream = new
FileOutputStream(sdImageMainDirectory.toString() +"/image.jpg");
BufferedOutputStream bos = new
BufferedOutputStream(fileOutputStream);
myImage.compress(CompressFormat.JPEG, quality, bos);
bos.flush();
bos.close();
}catch (FileNotFoundException e) {e.printStackTrace();} catch
(IOException e) {e.printStackTrace();}
return true;
}
public void takePicture()
{
camera.takePicture(null, mPictureCallback, mPictureCallback);
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en