android.hardware.Camera$EventHandler.handleMessage
Try this code and try to save image or video in background thread instead of UI
private PictureCallback mPicture = new PictureCallback() { @Override public void onPictureTaken(final byte[] data, Camera camera) { final File pictureFile = getOutputMediaFile(); if (pictureFile == null) { return; } Thread thread = new Thread() { @Override public void run() { try { FileOutputStream fos = new FileOutputStream(pictureFile); fos.write(data); fos.close(); } catch (Exception e) { e.printStackTrace(); } } }; thread.start(); } }; private File getOutputMediaFile() { File mediaStorageDir = new File( Environment.getExternalStorageDirectory(), "/Images"); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("Camera", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss") .format(new Date()); File mediaFile; String image_path = mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"; mediaFile = new File(image_path); return mediaFile; }
When data dose not created.You can not use bitmap.
That means a little time need to create image.so bitmapcreate return null.
I think PictureCallback runs like a Thread
To resolve this problem. change this code
Bitmap bMap= BitmapFactory.decodeFile(cPath); Bitmap out = Bitmap.createScaledBitmap(bMap, 1024, 768, true);
To
Bitmap bMap = BitmapFactory.decodeByteArray(data, 0,.length); Bitmap out = Bitmap.createScaledBitmap(bMap, 1024, 768, true);
That code convert byte[] to bitmap (see data in picturecallback );
The camera API reference: Camera API tutorials