@SuppressWarnings("deprecation") // setPreviewFrameRate, getPreviewFrameRate @Override public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { if (camera == null) { // Camera wasn't opened successfully? Log.e(TAG, "No camera in surfaceChanged"); return; } Log.i(TAG, "Surfaced changed, setting up camera and starting preview"); String camResolution = PreferenceManager.getDefaultSharedPreferences(getContext()) .getString( "pref_cameraResolution", getResources().getString(R.string.pref_defaultValue_cameraResolution)); String[] dims = camResolution.split("x", 2); Camera.Parameters parameters = camera.getParameters(); parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1])); parameters.setPreviewFrameRate(30); camera.setParameters(parameters); parameters = camera.getParameters(); captureWidth = parameters.getPreviewSize().width; captureHeight = parameters.getPreviewSize().height; captureRate = parameters.getPreviewFrameRate(); int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat PixelFormat pixelinfo = new PixelFormat(); PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo); int cameraIndex = 0; boolean cameraIsFrontFacing = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); cameraIndex = Integer.parseInt( PreferenceManager.getDefaultSharedPreferences(getContext()) .getString("pref_cameraIndex", "0")); Camera.getCameraInfo(cameraIndex, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) cameraIsFrontFacing = true; } mParent.onCameraConfigured(captureWidth, captureHeight, w, h); int bufSize = captureWidth * captureHeight * pixelinfo.bitsPerPixel / 8; // For the default NV21 format, bitsPerPixel = 12. Log.i( TAG, "Camera buffers will be " + captureWidth + "x" + captureHeight + "@" + pixelinfo.bitsPerPixel + "bpp, " + bufSize + "bytes."); cameraWrapper = new CameraWrapper(camera); cameraWrapper.configureCallback( this, true, 10, bufSize); // For the default NV21 format, bitsPerPixel = 12. camera.startPreview(); if (listener != null) listener.cameraPreviewStarted( captureWidth, captureHeight, captureRate, cameraIndex, cameraIsFrontFacing); }