问题
I have a custom camera in the app and the images that are taken on most of the devices look good but on galaxy nexus the story is different. Images are blurry in Galaxy nexus. I see grainy lines on Motorola Atrix as well. But Droid X, Droid Razr, HTC Evo, HTC incredible are showing good results. Any idea why it would happpen? This is what I have so far. P.S.: I am using Auto focus in the activity.
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) {
}
}
回答1:
Its been a while I solved this problem. If I remember it correctly, I solved by adding the below lines while getting the camera instance.
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);
回答2:
Have you tried this one ?
if (cameraParameters.getSupportedSceneModes().contains(Camera.Parameters.SCENE_MODE_STEADYPHOTO)) {
cameraParameters.setSceneMode(Camera.Parameters.SCENE_MODE_STEADYPHOTO);
}
来源:https://stackoverflow.com/questions/11943800/images-from-custom-camera-are-blurry-on-galaxy-nexus