2011-11-19 39 views
3

我已經制作了一個應用程序,它在每一分鐘捕獲圖像並將其上傳到服務器。 該應用程序在手機上運行良好,但是當我在平板電腦上運行相同的應用程序時,它捕獲圖像並上傳一次;下次顯示黑屏。Android圖像捕捉funationality不能再工作

我現在該做什麼?

回答

5

我找到了解決方案。我的相機在預覽時無法設置參數。 所以我發現了一個很好的功能來設置平板電腦的相機參數。

private Size getOptimalPreviewSize(List<Size> sizes, int w, int h) { 
    // TODO Auto-generated method stub 
    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; 
}