Android Image捕获功能不再适用于其他时间

Dhr*_*sha 3 android image-uploading android-camera

我创建了一个应用程序,每隔一分钟捕获一次图像并将其上传到服务器.该应用程序在手机上运行良好,但当我在平板电脑上运行相同的应用程序时,它会捕获图像并上传一次; 下次它显示黑屏.

我现在应该怎么做?

Dhr*_*sha 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;
}
Run Code Online (Sandbox Code Playgroud)