我的问题捕获图像在我的应用程序中显得模糊,因为使用设备相机组件捕获的图像看起来很好 - 一旦用户点击捕获按钮,就会出现自动缩放效果。有人可以帮助我实现这种情况应该如何以及在哪里应用。
这是代码:
public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) {
// Now that the size is known, set up the camera parameters and begin
// the preview.
Camera.Parameters parameters = camera.getParameters();
Integer version = Integer.parseInt(Build.VERSION.SDK);
if(version > Build.VERSION_CODES.ECLAIR_MR1)
{
Log.d(TAG, "------> version greater than eclari 2.1");
List<Size> sizes = parameters.getSupportedPreviewSizes();
Size optimalSize = getOptimalPreviewSize(sizes, width, height);
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
}
else
{
Log.d(TAG, "------> version less than eclari 2.1");
parameters.setPreviewSize(ApplicationInitiator.screenW,ApplicationInitiator.screenH);
}
List<String> focusModes = parameters.getSupportedFocusModes();
if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO))
{
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
}
parameters.setJpegQuality(100);
camera.setParameters(parameters);
camera.startPreview();
}
答案 0 :(得分:11)
好吧,在你的文字中你谈到捕捉一个图像,但我没有在你的代码中看到任何关于拍照的事情,无论如何,如果你想获得一张专注的照片,你要做的就是注册一个AutoFocusCallback获得焦点时拍照:
Camera.AutoFocusCallback mAutoFocusCallback = new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
camera.takePicture(null, null, mPictureCallbackRaw);
}
};
Camera.PictureCallback mPictureCallbackRaw = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera c) {
// (...)
}
};
public void takeFocusedPicture() {
mCamera.autoFocus(mAutoFocusCallback);
}