1
我知道這個話題已經出現了很多次,所以我不能得到任何解決方案的工作。我正在建立一個照相亭類型的應用程序,並且除了相機的實時取景失真(圖像從上到下),所有東西都可以正常工作,這會影響最終結果,因爲只有相機預覽才能使疊加層失真。圖像在正確的高寬比下也能很好地保存。貝婁是代碼,如果需要,我可以發佈更多。圖像失真在相機預覽
Parameters params = camera.getParameters();
List<Camera.Size> supportedPreviewSizes = params.getSupportedPreviewSizes();
Camera.Size camPreviewSize = getOptimalPreviewSize(supportedPreviewSizes, width , height);
Log.d(TAG+"--",height +" : " + width);//display height and width
Log.d(TAG+"--",camPreviewSize.height +" : " + camPreviewSize.width);
params.setPreviewSize(camPreviewSize.width ,camPreviewSize.height);
camera.setPreviewDisplay(surfaceHolder);
camera.startPreview();
Calcuate預覽大小
private Camera.Size getOptimalPreviewSize(List<Camera.Size> sizes, int w, int h) {
final double ASPECT_TOLERANCE = 0.1;
double targetRatio=(double)h/w;
if (sizes == null) return null;
Camera.Size optimalSize = null;
double minDiff = Double.MAX_VALUE;
int targetHeight = h;
for (Camera.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);
}
}
if (optimalSize == null) {
minDiff = Double.MAX_VALUE;
for (Camera.Size size : sizes) {
if (Math.abs(size.height - targetHeight) < minDiff) {
optimalSize = size;
minDiff = Math.abs(size.height - targetHeight);
}
}
}
return optimalSize;
}
改變的params.setPreviewSize()
值似乎沒有任何效果