3

我在应用程序中有一个自定义相机,在大多数设备上拍摄的图像看起来都不错,但在 Galaxy Nexus 上,情况就不同了。Galaxy nexus 中的图像模糊不清。我在摩托罗拉 Atrix 上也看到了颗粒状线条。但 Droid X、Droid Razr、HTC Evo、HTC 不可思议都显示出不错的成绩。知道为什么会发生吗?这就是我到目前为止所拥有的。PS:我在活动中使用自动对焦。

public class CameraPreview extends SurfaceView implements
    SurfaceHolder.Callback {

private SurfaceHolder mHolder;
private Camera mCamera;

public CameraPreview(Context context, Camera camera) {
    super(context);
    mCamera = camera;
    mHolder = getHolder();
    mHolder.addCallback(this);
    mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    // The Surface has been created, now tell the camera where to draw the
    // preview.
    try {
        mCamera.setPreviewDisplay(holder);
        Camera.Parameters parameters = mCamera.getParameters();
        List<String> focusModes = parameters.getSupportedFocusModes();
        if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
        }

        parameters.set("orientation", "portrait");

        mCamera.setDisplayOrientation(90);
        mCamera.setParameters(parameters);
        mCamera.startPreview();
    } catch (IOException e) {
    }
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {

}

@Override
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

    if (mHolder.getSurface() == null) {
        // preview surface does not exist
        return;
    }
    // stop preview before making changes
    try {
        mCamera.stopPreview();
    } catch (Exception e) {
        // ignore: tried to stop a non-existent preview
    }

    try {
        mCamera.startPreview();

    } catch (Exception e) {
    }
}
4

2 回答 2

4

我解决了这个问题已经有一段时间了。如果我没记错的话,我通过在获取相机实例时添加以下行来解决。

Camera.Parameters parameters = camera.getParameters();
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();
int w = 0, h = 0;
for (Size size : sizes) {
   if (size.width > w || size.height > h) {
      w = size.width;
      h = size.height;
   }

 }
 parameters.setPictureSize(w, h);
于 2013-07-02T05:17:33.957 回答
0

你试过这个吗?

if (cameraParameters.getSupportedSceneModes().contains(Camera.Parameters.SCENE_MODE_STEADYPHOTO)) {
   cameraParameters.setSceneMode(Camera.Parameters.SCENE_MODE_STEADYPHOTO);
}
于 2017-09-12T17:27:47.113 回答