http://blog.csdn.net/leeo1010/article/details/45566013
问题描述:
预览图像被拉伸变形
问题原因:
由于预览图像大小跟SurfaceView 大小不一致引起
解决方法:
获取系统支持的所有预览尺寸[getSupportedPictureSizes],然后再取一个比较接近的尺寸进行设置[setPreviewSize]
选择最佳尺寸方法:
private Point getBestCameraResolution(Camera.Parameters parameters, Point screenResolution){
float tmp = 0f;
float mindiff = 100f;
float x_d_y = (float)screenResolution.x / (float)screenResolution.y;
Size best = null;
List<Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
for(Size s : supportedPreviewSizes){
tmp = Math.abs(((float)s.height/(float)s.width)-x_d_y);
if(tmp<mindiff){
mindiff = tmp;
best = s;
}
}
return new Point(best.width, best.height);
}