相机预览在三星银河盛大中模糊不清,但在三星s3中表现不错

时间:2014-04-18 17:48:13

标签: android android-camera

嘿,我刚刚启动了相机预览程序,代码工作正常 但是在我的设备(三星galaxy Grand)中,相机有点模糊但是当我在另一台设备(三星S3)中运行时相机质量很好,我的代码有问题吗?

MainActivity.java

package com.practise.camera;
import java.io.IOException;
import android.app.Activity;
import android.graphics.PixelFormat; 
import android.hardware.Camera;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity implements SurfaceHolder.Callback {
SurfaceHolder mSurfaceHolder;
SurfaceView mSurfaceView;
public Camera mCamera;
boolean mPreviewRunning;

/** Called when the activity is first created. */

@Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     requestWindowFeature(Window.FEATURE_NO_TITLE);
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
     WindowManager.LayoutParams.FLAG_FULLSCREEN);
     setContentView(R.layout.activity_main);
     mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
     mSurfaceHolder = mSurfaceView.getHolder();
     mSurfaceHolder.addCallback(this);
     mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);


 }

@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
        if (mPreviewRunning) {
            mCamera.stopPreview();
        }
        Camera.Parameters p = mCamera.getParameters();
        mCamera.setParameters(p);
        try {
            mCamera.setPreviewDisplay(arg0);

        } catch (IOException e) {
            e.printStackTrace();
        }
        mCamera.startPreview();
        mPreviewRunning = true;
}

@Override
public void surfaceCreated(SurfaceHolder holder) {
    mCamera = Camera.open();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
    mCamera.stopPreview();
    mPreviewRunning = false;
    mCamera.release();
}

Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
    public void onPictureTaken(byte[] imageData, Camera c) {
    }
};



}

activity_main.xml中

<LinearLayout 
android:id="@+id/LinearLayout01"
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical">

 <SurfaceView 
    android:id="@+id/surface_camera"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"        
    />
</LinearLayout>

代码的问题在哪里......除了两台设备外,我没有在任何设备上查看它

相机预览的结果为Camera preview application

但内置的相机应用程序很好,它显示为Inbuilt Phone camera application

1 个答案:

答案 0 :(得分:1)

您可以尝试告诉相机自动对焦。在surfaceChanged例程中添加与此类似的内容。

// newer phones can be told to auto focus before taking the picture
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    if ( p.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) ) {
        p.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    }
}

mCamera.setParameters(p);
mCamera.startPreview();