@CalledByNative public static CaptureFormat[] getDeviceSupportedFormats(int id) { Camera camera; try { camera = Camera.open(id); } catch (RuntimeException ex) { Log.e(TAG, "Camera.open: " + ex); return null; } Camera.Parameters parameters = camera.getParameters(); ArrayList<CaptureFormat> formatList = new ArrayList<CaptureFormat>(); // getSupportedPreview{Formats,FpsRange,PreviewSizes}() returns Lists // with at least one element, but when the camera is in bad state, they // can return null pointers; in that case we use a 0 entry, so we can // retrieve as much information as possible. List<Integer> pixelFormats = parameters.getSupportedPreviewFormats(); if (pixelFormats == null) { pixelFormats = new ArrayList<Integer>(); } if (pixelFormats.size() == 0) { pixelFormats.add(ImageFormat.UNKNOWN); } for (Integer previewFormat : pixelFormats) { int pixelFormat = AndroidImageFormatList.ANDROID_IMAGEFORMAT_UNKNOWN; if (previewFormat == ImageFormat.YV12) { pixelFormat = AndroidImageFormatList.ANDROID_IMAGEFORMAT_YV12; } else if (previewFormat == ImageFormat.NV21) { continue; } List<int[]> listFpsRange = parameters.getSupportedPreviewFpsRange(); if (listFpsRange == null) { listFpsRange = new ArrayList<int[]>(); } if (listFpsRange.size() == 0) { listFpsRange.add(new int[] {0, 0}); } for (int[] fpsRange : listFpsRange) { List<Camera.Size> supportedSizes = parameters.getSupportedPreviewSizes(); if (supportedSizes == null) { supportedSizes = new ArrayList<Camera.Size>(); } if (supportedSizes.size() == 0) { supportedSizes.add(camera.new Size(0, 0)); } for (Camera.Size size : supportedSizes) { formatList.add( new CaptureFormat(size.width, size.height, (fpsRange[0] + 999) / 1000, pixelFormat)); } } } camera.release(); return formatList.toArray(new CaptureFormat[formatList.size()]); }
@Override public void surfaceCreated(SurfaceHolder arg0) { camera = Camera.open(); Camera.Parameters params = camera.getParameters(); camera.setDisplayOrientation(90); params.setRotation(90); params.set("orientation", "landscape"); params.set("rotation", 90); params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); Camera.Size previewSize = params.getPreviewSize(); List<Camera.Size> previewSizes = params.getSupportedPreviewSizes(); int i = 0; for (Camera.Size cs : previewSizes) { Log.d(MarvinActivity.TAG, "Camera - supports:(" + (i++) + ") " + cs.width + "x" + cs.height); } previewSize.width = 720; previewSize.height = 480; params.setSceneMode("portrait"); Log.d(MarvinActivity.TAG, "w: " + previewSize.width + " h: " + previewSize.height); List<Integer> formats = params.getSupportedPreviewFormats(); for (Integer format : formats) { Log.d(MarvinActivity.TAG, "Camera - supports preview format: " + format); } params.setPreviewSize(previewSize.width, previewSize.height); camera.setParameters(params); detectThread = new FaceDetectThread(context, user, params); detectThread.start(); camera.setPreviewCallback(detectThread); try { camera.setPreviewDisplay(cameraView.getHolder()); camera.startPreview(); Log.d(MarvinActivity.TAG, "preview started"); } catch (Exception e) { Log.e(MarvinActivity.TAG, e.getMessage(), e); } user.onEyeStarted(); }