【问题标题】:Android Image Capturing funationality does not work another timeAndroid Image Capture 功能再次无法正常工作
【发布时间】:2012-01-01 20:12:54
【问题描述】:

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

我现在该怎么办?

【问题讨论】:

    标签: android android-camera image-uploading


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 2020-10-28
      • 2013-11-06
      • 2013-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多