Camera Preview on Motorola Droid

In our application, a camera preview is displayed, and it seems to work fine on all phones, with the exception of the Motorola Droid, where we get an exception at runtime when configuring the camera settings:

    java.lang.RuntimeException: setParameters failed
   at android.hardware.Camera.native_setParameters(Native Method)
   at android.hardware.Camera.setParameters(Camera.java:611)
   at com.highwaynorth.andrometer.CameraPreviewSurfaceView.surfaceChanged(CameraPreviewSurfaceView.java:57)
   at android.view.SurfaceView.updateWindow(SurfaceView.java:460)
   at android.view.SurfaceView.dispatchDraw(SurfaceView.java:287)
   at android.view.ViewGroup.drawChild(ViewGroup.java:1525)

Here is the code for surfaceChanged (), which is mainly taken from APIDemos

public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
   // Now that the size is known, set up the camera parameters and begin
   // the preview.
   Camera.Parameters parameters = mCamera.getParameters();
   parameters.setPreviewSize(w, h);
   parameters.setPictureFormat(PixelFormat.JPEG);
   parameters.setPreviewFormat(PixelFormat.YCbCr_422_SP);
   parameters.setPreviewFrameRate(1);
   mCamera.setParameters(parameters);
   mCamera.startPreview();

}

Does anyone know what's wrong with how we set parameters that will throw an exception on a Motorola Droid?

+3
source share
3 answers

I can say that your problem is related to one of the following two lines:

parameters.setPreviewFormat(PixelFormat.YCbCr_422_SP);
parameters.setPreviewFrameRate(1);

, - , , DROID.

getSupportedPreviewFormats() getSupportedPreviewFrameRates() Camera.Parameters, , , . , Android 2.0, DROID/Milestone (, , Nexus One), . Android API, , Android 2.0 .

+2

, , , .

, DROID PixelFormat.YCbCr_422_I PixelFormat.YCbCr_420_SP

. getSupportedPreviewFormats()

0

, :

Motoblur 2.3 ( Droid2, DroidX Atrix Verizon).

, layout/capture.xml ViewfinderView :

<com.google.zxing.client.android.ViewfinderView
   android:id="@+id/viewfinder_view" 
   android:layout_width="fill_parent" 
   android:layout_height="fill_parent" 
   android:background="@color/transparent"
/>

, , Motoblur Android 2.3 ...

android:background="@color/transparent"

ViewFinder .

0

Source: https://habr.com/ru/post/1727917/


All Articles