【问题标题】:Samsung Galaxy S4 , Image gets corrupted while taking from camera三星 Galaxy S4,从相机拍摄时图像损坏
【发布时间】:2013-06-17 06:33:08
【问题描述】:

我在我的应用上使用相机。相机在三星 S3 之前的所有设备上都能完美运行。在所有其他设备上显示的图像都是正确的。

从 S4 获取图像时,图像被损坏,图像被保存为水平线。

我尝试更改分辨率和一切,但仍然存在问题。

任何帮助

【问题讨论】:

    标签: android android-layout galaxy samsung-mobile


    【解决方案1】:

    我一直在努力解决这个问题,我认为我发现了这个问题,至少在我的应用中 - 它与预览图像与捕获图像的纵横比有关。

    在我的例子中,我的代码是根据屏幕的纵横比找出理想的预览尺寸。 S4 是 1080p 手机,因此预览图像为 1920x1080,即 16:9 纵横比。但是我的代码被硬编码为捕获 4:3 的 1600x1200 图像,因为这就是我所需要的。但 1600x1200 不是 S4 支持的有效尺寸之一。

    在不设置大小的情况下,S4 捕捉到的最大大小为 4128x3096,为 4:3,但仍然出现线条。一旦我告诉相机拍摄一张 16:9 的照片,线条就消失了。在您的情况下,您可能需要调整预览的纵横比。

    这里有一些代码可以告诉你可用的尺寸。

        List<Camera.Size> previewSizes = p.getSupportedPreviewSizes();
    
        int i = 1;
    
        for (Size previewSize : previewSizes) {
            Log.v("DebugCamera", "previewSize " + i++ + " width: " + previewSize.width + " height: " + previewSize.height);
        }
    

    【讨论】:

      【解决方案2】:

      刚刚在 S4 上尝试过这段代码,它可以工作。试试看:

      private Camera.Size getBestPreviewSize(int width, int height)
      {
              Camera.Size result=null;    
              Camera.Parameters p = camera.getParameters();
              for (Camera.Size size : p.getSupportedPreviewSizes()) {
                  if (size.width<=width && size.height<=height) {
                      if (result==null) {
                          result=size;
                      } else {
                          int resultArea=result.width*result.height;
                          int newArea=size.width*size.height;
      
                          if (newArea>resultArea) {
                              result=size;
                          }
                      }
                  }
              }
          return result;
      
      }
      
      public void surfaceCreated(SurfaceHolder holder) {
          if(myCamera == null){
              myCamera = getCameraInstance();
          try {
              myCamera.setPreviewDisplay(holder);
          } catch (IOException e) {
              e.printStackTrace();
          }
        }
      }
      
      public void surfaceDestroyed(SurfaceHolder holder) {
          // empty. Take care of releasing the Camera preview in your activity.
          // Surface will be destroyed when we return, so stop the preview.
          if (myCamera != null)
          {
              myCamera.stopPreview();
              myCamera.setPreviewCallback(null);
              myCamera.release();
          }
      } 
      
      @Override
      public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
          //This line helped me set the preview Display Orientation to Portrait
                  //Only works API Level 8 and higher unfortunately.
      
          camera.setDisplayOrientation(90);
      
          Camera.Parameters parameters = camera.getParameters();
          Camera.Size size = getBestPreviewSize(width, height);
          parameters.setPreviewSize(size.width, size.height);
          camera.setParameters(parameters);
          camera.startPreview();
      
      }
      

      【讨论】:

        猜你喜欢
        • 2014-02-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-15
        • 2015-11-22
        • 1970-01-01
        • 1970-01-01
        • 2012-07-22
        相关资源
        最近更新 更多