【问题标题】:Samsung Galaxy S camera crash unexpectedly三星 Galaxy S 相机意外崩溃
【发布时间】:2012-03-11 13:38:39
【问题描述】:

我的应用程序在没有堆栈跟踪的情况下崩溃,就像here 所问的那样。我也在使用三星 Galaxy S。它可以很好地满足我对 HTC 的渴望。解决方案是“删除预览视图并重新实例化它”

但是,我创建的表面视图是通过这种方式完成的

camera = (SurfaceView) findViewById(R.id.cameraview);

我该如何解决这个问题或如何重新实例化这个 SurfaceView?

02-21 15:57:20.305: ERROR/SecCamera(2357): startPreview: get the first frame of the preview
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): startPreview : return startPreview 0
02-21 15:57:20.305: DEBUG/CameraHardwareSec(2357): MemoryHeapBase(fd(33), size(3686464), width(640), height(480))
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): CameraHardwareSec: mPostViewWidth = 640 mPostViewHeight = 480 mPostViewSize = 614400
02-21 15:57:20.305: ERROR/CameraHardwareSec(2357): CameraHardwareSec: mRawHeap : MemoryHeapBase(previewHeapSize(614408))
02-21 15:57:20.305: WARN/CameraService(2357): width(640), height(480), format:yuv420sp
02-21 15:57:20.328: ERROR/SecCamera(2357): fimc_v4l2_streamoff()
02-21 15:57:20.336: ERROR/SecCamera(2357): ERR(fimc_v4l2_streamoff):VIDIOC_STREAMOFF failed
02-21 15:57:20.336: ERROR/SecCamera(2357): int android::SecCamera::stopRecord()::1494 fail. errno: No such device
02-21 15:57:20.336: ERROR/CameraHardwareSec(2357): ERR(previewThread):Fail on mSecCamera->stopRecord()
02-21 15:57:20.363: WARN/CameraService(2357): startRecording (pid 2357)
02-21 15:57:20.367: WARN/CameraService(2357): startCameraMode(1) (pid 2357)
02-21 15:57:20.367: WARN/CameraService(2357): startRecordingMode (pid 2357)
02-21 15:57:20.367: DEBUG/SecCamera(2357): passed fmt = 842094164 found pixel format[8]: YUV 4:2:0 planar, Y/CbCr, Tiled
02-21 15:57:20.367: ERROR/SecCamera(2357): startRecord: m_recording_width = 320, m_recording_height = 240

【问题讨论】:

    标签: android camera


    【解决方案1】:

    嗯,我将固件升级到 2.3.3,现在可以使用了。

    【讨论】:

      【解决方案2】:

      我认为设置预览参数应该有一些问题。 试试下面。

      public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
      
      
      
      if (isPreviewRunning) {
          camera.stopPreview();
      }
      try{
      Camera.Parameters p = camera.getParameters();
      if(p!=null){
      List<Size> sizes = p.getSupportedPreviewSizes();
      Size optimalSize = getOptimalPreviewSize(sizes, w, h);
      p.setPreviewSize(optimalSize.width, optimalSize.height);
      camera.setParameters(p);
      
      camera.setPreviewDisplay(holder);;
      camera.startPreview();
      
      }
      } catch (IOException e) {
          // TODO Auto-generated catch block
      
      
          e.printStackTrace();
      }
      
      isPreviewRunning = true;
      }
      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;
      }
      public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
      
      
      
      if (isPreviewRunning) {
          camera.stopPreview();
      }
      try{
      Camera.Parameters p = camera.getParameters();
      if(p!=null){
      List<Size> sizes = p.getSupportedPreviewSizes();
      Size optimalSize = getOptimalPreviewSize(sizes, w, h);
      p.setPreviewSize(optimalSize.width, optimalSize.height);
      camera.setParameters(p);
      
      camera.setPreviewDisplay(holder);;
      camera.startPreview();
      
      }
      } catch (IOException e) {
          // TODO Auto-generated catch block
      
      
          e.printStackTrace();
      }
      
      isPreviewRunning = true;
      }
      

      私有大小 getOptimalPreviewSize(列表大小, 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;
      

      }

      将此代码放入您的surfaceChanged() 中。 getOptimalPreviewSize() 用于根据设备分辨率设置预览参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多