이 문제에 대한 한 가지 매우 이상한 해결책을 발견했습니다. 내 카메라 미리보기와 촬영 한 사진의 비율이 같으면 테스트 한 모든 장치에서 사진이 잘 보이게됩니다. 따라서 최적의 미리보기 크기를 얻은 후에는 같은 비율로 지원되는 그림 크기를 검색하고 있습니다.
이상하지만 작동합니다.
먼저 미리보기 크기를 가져와야합니다.
protected Size getOptimalPreviewSize(List<Size> sizes, int width, int height) {
Log.d(TAG, String
.format("getOptimalPreviewSize: width = %d, height = %d",
width, height));
final double ASPECT_TOLERANCE = 0.01;
final double targetRatio = (double) 4/3d;
if (sizes == null)
return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = height;
// Try to find an size match aspect ratio and size
double ratio;
Size size;
for (int i = 0; i < sizes.size(); i++) {
size = sizes.get(i);
ratio = (double) size.width/size.height;
if (Math.abs(ratio - targetRatio) > ASPECT_TOLERANCE)
continue;
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
// Cannot find the one match the aspect ratio, ignore the requirement
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (int i = 0; i < sizes.size(); i++) {
size = sizes.get(i);
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
if (optimalSize == null) {
Log.d(TAG, "Optimal size not found");
} else {
Log.d(TAG,
String.format(
"getOptimalPreviewSize result: width = %d, height = %d for input width = %d, height = %d",
optimalSize.width, optimalSize.height, width,
height));
}
return optimalSize;
}
그런 다음 미리보기에서 크기 비율이 같은 사진 크기를 가져와야합니다.
private Size getOptimalPictureSize() {
if (mCamera == null)
return null;
List<Size> cameraSizes = mCamera.getParameters()
.getSupportedPictureSizes();
Size optimalSize = mCamera.new Size(0, 0);
double previewRatio = (double) mPreviewSize.width/mPreviewSize.height;
for (Size size : cameraSizes) {
double ratio = (double) size.width/size.height;
if (Math.abs(ratio - previewRatio) > 0.01f)
continue;
if (size.height > optimalSize.height) {
optimalSize = size;
}
}
if (optimalSize.height == 0) {
for (Size size : cameraSizes) {
if (size.height > optimalSize.height) {
optimalSize = size;
}
}
}
return optimalSize;
}
그리고 이것이 Camera.Parametres
무엇 노출 보정 변경에 대한
Size optimalSize = getOptimalPictureSize();
Parameters params = mCamera.getParameters();
Log.d(TAG, "picture size " + optimalSize.width + " "
+ optimalSize.height);
params.setPictureSize(optimalSize.width, optimalSize.height);
mCamera.setParameters(params);
에 크기를 적용? 당신은'setExposureCompensation (int)'를 사용하여 수동으로 설정할 수있다. –
답변 해 주셔서 감사합니다. 내 앱은 다양한 종류의 번개에서 좋은 사진을 찍을 수 있어야하므로 자동 설정 만 사용하고 싶습니다. – rstk