1、对于一些,像HTC,当自定义Camera时,调用Camera.Parameters的parameters.setPreviewSize(width,height)方法时,如果width和height为奇数情况下,那么会出现黑屏现象,解决办法可参考SDK提供的ApiDemos中关于Camera的例子:Listsizes=parameters.getSupportedPreviewSizes();SizeoptimalSize=getOptimalPreviewSize(sizes,w,h);parameters.setPreviewSize(optimalSize.width,optimalSi
2、ze.height);同时,在HTC中,设置parameters.setPictureSize(width,height)属性,也会导致黑屏,而在三星上那么没有问题。还有如果设置setPreviewSize属性的宽高错误的话,拍出的照片也会存在失真等Bug,所以遇到适配问题时,最好的办法就是不设置PreviewSize和PictureSize属性。getOptimalPreviewSize方法privateSizegetOptimalPreviewSize(Listsizes,intw,inth)finaldoubleASPECT_TOLERANCE=0.05;doubletargetRati
3、o=(double)w/h;if(sizes=null)returnnull;SizeoptimalSize=null;doubleminDiff=Double.MAX_VALUE;inttargetHeight=h;/Trytofindansizematchaspectratioandsizefor(Sizesize:sizes)doubleratio=(double)size.width/size.height;if(Math.abs(ratio-targetRatio)ASPECT_TOLERANCE)continue;if(Math.abs(size.height-targetHeig
4、ht)minDiff)optimalSize=size;minDiff=Math.abs(size.height-targetHeight);/Cannotfindtheonematchtheaspectratio,ignoretherequirementif(optimalSize=null)minDiff=Double.MAX_VALUE;for(Sizesize:sizes)if(Math.abs(size.height-targetHeight)minDiff)optimalSize=size;minDiff=Math.abs(size.height-targetHeight);returnoptimalSize;