标签:android blog http strong os width
List<Size> sizes = parameters.getSupportedPreviewSizes();
Size optimalSize = getOptimalPreviewSize(sizes, w, h);
parameters.setPreviewSize(optimalSize.width, optimalSize.height);
同时,在HTC手机中,设置parameters.setPictureSize(width,height)属性,也会导致黑屏,而在三星手机上则没有问题。还有如果设置setPreviewSize属性的宽高错误的话,拍出的照片也会存在失真等Bug,所以遇到适配问题时,最好的办法就是不设置PreviewSize和PictureSize属性。
getOptimalPreviewSize方法
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 size
for (Size size : sizes) {
double 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 (Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
android 自定义照相机Camera黑屏 (转至 http://blog.csdn.net/chuchu521/article/details/8089058),布布扣,bubuko.com
android 自定义照相机Camera黑屏 (转至 http://blog.csdn.net/chuchu521/article/details/8089058)
标签:android blog http strong os width
原文地址:http://www.cnblogs.com/kobe8/p/3850889.html