I am trying to set the camera preview size and also the image size in the Camera Preview class. But, my Log.v to show the camera preview size and image size does not display anything in the logcat. So, I have no idea whether the camera preview and image is set to the size I wanted. I am using Eclipse.
I am calling the setCamera() from the Camera Preview constructor.
public CameraPreview(Context context, Camera camera) {
super(context);
mCamera = camera;
setCamera(mCamera);
// Install a SurfaceHolder.Callback so we get notified when the
// underlying surface is created and destroyed.
mHolder = getHolder();
mHolder.addCallback(this);
// deprecated setting, but required on Android versions prior to 3.0
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
我设置的相机有Log.v来显示预览的大小和图像大小。
public void setCamera(Camera camera) {
if (mCamera == camera) { return; }
mCamera = camera;
if (mCamera != null) {
List<Size> localSizes = mCamera.getParameters().getSupportedPreviewSizes();
mSupportedPreviewSizes = localSizes;
//parameters.setPreviewSize(mSupportedPreviewSizes.get(0).width, mSupportedPreviewSizes.get(0).height);
parameters.setPreviewSize(640, 480);
mCamera.setParameters(parameters);
parameters.setPictureSize(640, 480);
mCamera.setParameters(parameters);
Log.v(preview, "get preview size: " + parameters.getPreviewSize()
+ "get picture size: " +parameters.getPictureSize());
requestLayout();
try {
mCamera.setPreviewDisplay(mHolder);
} catch (IOException e) {
e.printStackTrace();
}
/*
Important: Call startPreview() to start updating the preview surface. Preview must
be started before you can take a picture.
*/
mCamera.startPreview();
}
}