其他分享
首页 > 其他分享> > Android Image捕获功能不再适用于其他时间

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

作者:互联网

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

我现在应该怎么做?

解决方法:

我找到了解决方法.我的相机无法在预览时设置参数.
所以我找到了一个很好的功能来设置平板电脑的相机参数.

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;
}

标签:image-uploading,android,android-camera
来源: https://codeday.me/bug/20190902/1793114.html