我在相机应用程序上拍摄基本照片.当我获得最佳的最佳预览尺寸时,我遇到了问题.
事实上,有了这个第一个代码:
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (isPreviewRunning) {
mCamera.stopPreview();
}
Camera.Parameters parameters = mCamera.getParameters();
mCamera.setParameters(parameters);
mCamera.startPreview();
isPreviewRunning = true;
}
Run Code Online (Sandbox Code Playgroud)
图片质量很好:
http://img689.imageshack.us/i/04042011172937.jpg/
但是,使用此代码:
private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.05;
double targetRatio = (double) w / h;
if (sizes == null) return null;
Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
// Try to find an size match aspect ratio and …Run Code Online (Sandbox Code Playgroud)