在我的应用中,我打开相机供用户拍摄文字图片。不幸的是,自动对焦根本无法工作,并且在s7上图像非常模糊。我只是复制代码,也不是很了解代码。请在下面的代码中找到:
mCamera = getCameraInstance();
Camera.Parameters params = mCamera.getParameters();
params.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
//params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
Camera.Size desiredSize = getPictureSize(params.getSupportedPictureSizes());
System.out.println(desiredSize.width);
params.setPictureSize(desiredSize.width, desiredSize.height);
mCamera.setParameters(params);
mPreview = new CameraPreview(this, mCamera);
FrameLayout preview = findViewById(R.id.camera_preview);
preview.addView(mPreview);
rotation = CameraPreview.correctCameraDisplayOrientation(MainActivity.this, mCamera);
apiInterface = RetrofitInstance.getRetrofitInstance().create(ApiInterface.class);
Bundle extras = getIntent().getExtras();
if(extras!=null){
Uri imgUri = account.getPhotoUrl();
new ImageLoadTask(imgUri, toolbar).execute();
}
// }
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager =
(SearchManager) getSystemService(Context.SEARCH_SERVICE);
SearchView searchView =
(SearchView) menu.findItem(R.id.action_search).getActionView();
searchView.setSearchableInfo(
searchManager.getSearchableInfo(getComponentName()));
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
// searchView.getSuggestionsAdapter().setDropDownViewTheme(this.getTheme());
// }
return true;
}
private Camera.Size getPictureSize(List<Camera.Size> sizes) {
for (Camera.Size size : sizes) {
if ((size.width * size.height) / 1024000 <= 2.5) {
return size;
}
}
return null;
现在有人在这里出什么问题吗?我非常感谢您的帮助!
答案 0 :(得分:0)
您需要将焦点放在相机上。使用以下代码设置焦点
parameters = mCamera.getParameters();
if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
} else {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
}
parameters.setJpegQuality(100);