コード例 #1
0
  /**
   * Attempts to find a preview size that matches the provided width and height (which specify the
   * dimensions of the encoded video). If it fails to find a match it just uses the default preview
   * size.
   *
   * <p>TODO: should do a best-fit match.
   */
  private static void choosePreviewSize(Camera.Parameters parms, int width, int height) {
    // We should make sure that the requested MPEG size is less than the preferred
    // size, and has the same aspect ratio.
    Camera.Size ppsfv = parms.getPreferredPreviewSizeForVideo();
    if (ppsfv != null) {
      Log.d(TAG, "Camera preferred preview size for video is " + ppsfv.width + "x" + ppsfv.height);
    }

    // for (Camera.Size size : parms.getSupportedPreviewSizes()) {
    //    Log.d(TAG, "supported: " + size.width + "x" + size.height);
    // }

    for (Camera.Size size : parms.getSupportedPreviewSizes()) {
      if (size.width == width && size.height == height) {
        parms.setPreviewSize(width, height);
        return;
      }
    }

    Log.w(TAG, "Unable to set preview size to " + width + "x" + height);
    if (ppsfv != null) {
      parms.setPreviewSize(ppsfv.width, ppsfv.height);
    }
    // else use whatever the default size is
  }
コード例 #2
0
ファイル: CameraObject.java プロジェクト: arissetyawan/rhodes
  @SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  @Override
  public ISize setPreviewSize(int width, int height) {
    Camera camera = getCamera();
    Camera.Parameters parameters = camera.getParameters();
    List<android.hardware.Camera.Size> sizes = camera.getParameters().getSupportedPictureSizes();
    android.hardware.Camera.Size maxSize = sizes.get(0);
    if (getActualPropertyMap().containsKey("desiredWidth")
        || getActualPropertyMap().containsKey("desiredHeight")) {
      int desired_width = Integer.parseInt(getActualPropertyMap().get("desiredWidth"));
      int desired_height = Integer.parseInt(getActualPropertyMap().get("desiredHeight"));
      if (desired_width > 0
          && desired_width <= maxSize.width
          && desired_height > 0
          && desired_height <= maxSize.height) {
        Camera.Size previewSize =
            getOptimalPreviewSize(
                parameters.getSupportedPictureSizes(), desired_width, desired_height);
        Logger.T(TAG, "Selected size: " + previewSize.width + "x" + previewSize.height);
        parameters.setPreviewSize(previewSize.width, previewSize.height);
      } else if (desired_width > maxSize.width || desired_height > maxSize.height) {
        final Camera.Parameters newParam = parameters;
        final android.hardware.Camera.Size newMaxSize = sizes.get(0);
        RhodesActivity.safeGetInstance()
            .runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {
                    // TODO Auto-generated method stub
                    newParam.setPreviewSize(newMaxSize.width, newMaxSize.height);
                  }
                });
      } else {
        parameters.setPreviewSize(320, 240);
      }
    } else {
      Camera.Size previewSize =
          getOptimalPreviewSize(parameters.getSupportedPictureSizes(), width, height);
      Logger.T(TAG, "Selected size: " + previewSize.width + "x" + previewSize.height);
      parameters.setPreviewSize(previewSize.width, previewSize.height);
    }
    camera.stopPreview();
    try {
      camera.setParameters(parameters);
    } catch (RuntimeException e) {
      e.printStackTrace();
    }
    camera.startPreview();

    return new CameraSize(camera.getParameters().getPreviewSize());
  }
コード例 #3
0
  private void setupCamera() {
    Camera.Parameters parameters = mCamera.getParameters();
    List<Camera.Size> sizes = mCamera.getParameters().getSupportedPreviewSizes();

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    Resources stringResources = getResources();

    int cameraIndex =
        Integer.decode(
            prefs.getString(stringResources.getString(R.string.shared_prefs_camera_list), "0"));

    int cameraResolutionsIndex =
        Integer.decode(
            prefs.getString(
                String.format(
                    stringResources.getString(R.string.shared_prefs_camera_resolution_key),
                    cameraIndex),
                "0"));
    Camera.Size list = sizes.get(cameraResolutionsIndex);
    mPreviewWidth = list.width;
    mPreviewHeight = list.height;

    parameters.setPreviewFrameRate(30);
    parameters.setPreviewSize(mPreviewWidth, mPreviewHeight);

    setCameraFocusMode(parameters);

    setCameraWhiteBalanceMode(parameters);

    try {
      mCamera.setParameters(parameters);
    } catch (RuntimeException re) {
      re.printStackTrace();
      Log.e(TAG, "Unable to set Camera Parameters");
      Log.i(TAG, "Falling back to setting just the camera preview");
      parameters = mCamera.getParameters();
      parameters.setPreviewSize(mPreviewWidth, mPreviewHeight);
      try {
        mCamera.setParameters(parameters);
      } catch (RuntimeException re2) {
        re2.printStackTrace();
        Log.e(
            TAG,
            "Problem with camera configuration, unable to set "
                + "Camera Parameters. Camera not available.");
      }
    }

    mPreviewWidth = mCamera.getParameters().getPreviewSize().width;
    mPreviewHeight = mCamera.getParameters().getPreviewSize().height;
  }
コード例 #4
0
ファイル: CameraSurface.java プロジェクト: ocrenaka/around_me
 @SuppressWarnings("deprecation")
 public void surfaceChanged(SurfaceHolder surfaceholder, int i, int j, int k) {
   android.hardware.Camera.Parameters parameters = camera.getParameters();
   List list;
   float f;
   list = Compatibility.getSupportedPreviewSizes(parameters);
   f = (float) j / (float) k;
   float f1;
   int l;
   int i1;
   f1 = 0.0F;
   l = 0;
   i1 = 0;
   Iterator iterator = list.iterator();
   while (true) {
     if (iterator.hasNext()) {
       android.hardware.Camera.Size size = (android.hardware.Camera.Size) iterator.next();
       float f2 = (float) size.width / (float) size.height;
       if (f - f2 > f - f1) {
         continue; /* Loop/switch isn't completed */
       }
       if (size.width > j || size.width < l) {
         continue; /* Loop/switch isn't completed */
       }
       f1 = f2;
       try {
         l = size.width;
         i1 = size.height;
         continue; /* Loop/switch isn't completed */
       } catch (Exception exception1) {
       }
       try {
         parameters.setPreviewSize(480, 320);
         camera.setParameters(parameters);
         camera.startPreview();
         return;
       } catch (Exception exception) {
         exception.printStackTrace();
       }
       return;
     } else {
       if (l == 0 || i1 == 0) {
         l = 480;
         i1 = 320;
       }
       parameters.setPreviewSize(l, i1);
       break;
     }
   }
 }
コード例 #5
0
 public void onSurfaceTextureAvailable(
     SurfaceTexture paramSurfaceTexture, int paramInt1, int paramInt2) {
   if (VideoCaptureFragment.h(a) == null) {
     VideoCaptureFragment.a(a, Camera.open());
     Object localObject1 = VideoCaptureFragment.h(a).getParameters();
     Object localObject2 = VideoCaptureFragment.i(a);
     Camera localCamera = VideoCaptureFragment.h(a);
     localCamera.getClass();
     localObject2 = new Camera.Size(localCamera, videoFrameWidth, videoFrameHeight);
     if (((Camera.Parameters) localObject1).getSupportedPreviewSizes().contains(localObject2)) {
       ((Camera.Parameters) localObject1).setPreviewSize(width, height);
       VideoCaptureFragment.h(a).setParameters((Camera.Parameters) localObject1);
     }
     localObject1 = ((Camera.Parameters) localObject1).getPreviewSize();
     VideoCaptureFragment.a(a, width, height);
     VideoCaptureFragment.h(a).setDisplayOrientation(VideoCaptureFragment.j(a));
     try {
       VideoCaptureFragment.h(a).setPreviewTexture(paramSurfaceTexture);
       VideoCaptureFragment.h(a).startPreview();
       paramSurfaceTexture = VideoCaptureFragment.h(a).getParameters().getSupportedFocusModes();
       if (CameraWrangler.a(VideoCaptureFragment.h(a))) {
         VideoCaptureFragment.h(a).autoFocus(null);
         return;
       }
       if (paramSurfaceTexture.contains("continuous-video")) {
         paramSurfaceTexture = VideoCaptureFragment.h(a).getParameters();
         paramSurfaceTexture.setFocusMode("continuous-video");
         VideoCaptureFragment.h(a).setParameters(paramSurfaceTexture);
         return;
       }
     } catch (IOException paramSurfaceTexture) {
       YelpLog.error(paramSurfaceTexture);
     }
   }
 }
コード例 #6
0
ファイル: CameraActivity.java プロジェクト: cessien/memoji
  @Override
  public void surfaceCreated(SurfaceHolder holder) {
    try {
      // open the camera
      camera = Camera.open(1);
    } catch (RuntimeException e) {
      // check for exceptions
      System.err.println(e);
      return;
    }
    Camera.Parameters param;
    param = camera.getParameters();

    // modify parameter
    param.setPreviewSize(352, 288);
    camera.setParameters(param);
    try {
      // The Surface has been created, now tell the camera where to draw
      // the preview.
      camera.setPreviewDisplay(surfaceHolder);
      camera.setDisplayOrientation(90);
      camera.startPreview();
    } catch (Exception e) {
      // check for exceptions
      System.err.println(e);
      return;
    }
  }
コード例 #7
0
 private void initCamera() {
   if (!isPreview) {
     camera = Camera.open();
   }
   if (camera != null && !isPreview) {
     streamIt = new StreamIt();
     try {
       Camera.Parameters parameters = camera.getParameters();
       parameters.setPreviewSize(screenWidth, screenHeight); // 设置预览照片的大小	
       parameters.setPreviewFpsRange(20, 30); // 每秒显示20~30帧	
       parameters.setPictureFormat(ImageFormat.NV21); // 设置图片格式	
       parameters.setPictureSize(screenWidth, screenHeight); // 设置照片的大小
       camera.setPreviewDisplay(surfaceHolder); // 通过SurfaceView显示取景画面
       camera.setPreviewCallback(streamIt); // 设置回调的类	
       camera.startPreview(); // 开始预览	
       camera.autoFocus(null); // 自动对焦
     } catch (Exception e) {
       e.printStackTrace();
     }
     isPreview = true;
     Thread postThread2 = new Thread(new postThread());
     postThread2.start();
     System.out.println("线程启动了@@@@@@@@@@@@@@@@@@@@@@@@@@");
   }
 }
コード例 #8
0
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    Log.e(TAG, "surfaceChanged => w=" + w + ", h=" + h);
    // If your preview can change or rotate, take care of those events here.
    // Make sure to stop the preview before resizing or reformatting it.
    if (mHolder.getSurface() == null) {
      // preview surface does not exist
      return;
    }

    // stop preview before making changes
    try {
      mCamera.stopPreview();
    } catch (Exception e) {
      // ignore: tried to stop a non-existent preview
    }

    // set preview size and make any resize, rotate or reformatting changes here
    // start preview with new settings
    try {
      Camera.Parameters parameters = mCamera.getParameters();

      /* INSERT ZOOM HERE */

      parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
      parameters.setRotation(90);
      mCamera.setParameters(parameters);
      mCamera.setDisplayOrientation(90);

      mCamera.setPreviewDisplay(mHolder);
      mCamera.startPreview();

    } catch (Exception e) {
      Log.d(TAG, "Error starting camera preview: " + e.getMessage());
    }
  }
コード例 #9
0
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    if (mHolder.getSurface() == null) {
      // preview surface does not exist
      return;
    }

    // stop preview before making changes
    try {
      mCamera.stopPreview();
    } catch (Exception e) {
      // ignore: tried to stop a non-existent preview
    }

    // Sets preview size.
    Camera.Parameters parameters = mCamera.getParameters();
    List<Camera.Size> sizes = parameters.getSupportedPreviewSizes();
    Camera.Size cs = sizes.get(0);
    parameters.setPreviewSize(cs.width, cs.height);
    mCamera.setParameters(parameters);

    // start preview with new settings
    try {
      mCamera.setPreviewDisplay(mHolder);
      mCamera.startPreview();

    } catch (Exception e) {
      Log.d(TAG, "Error starting camera preview: " + e.getMessage());
    }
    Log.e(TAG, "SurfaceChanged.");
  }
コード例 #10
0
 public void setupCameraParameters() {
   Camera.Size optimalSize = getOptimalPreviewSize();
   Camera.Parameters parameters = mCamera.getParameters();
   parameters.setPreviewSize(optimalSize.width, optimalSize.height);
   mCamera.setParameters(parameters);
   adjustViewSize(optimalSize);
 }
コード例 #11
0
ファイル: AzCameraClass.java プロジェクト: zgljl2012/AzCamera
 /** 给摄像头设置好一系列相关参数,并开始预览 */
 private void initCamera() {
   azLog.log("isPreView", "" + isPreview);
   if (mCamera != null && !isPreview) {
     try {
       Camera.Parameters parameters = mCamera.getParameters();
       // 设置预览照片的大小
       parameters.setPreviewSize(mPreviewWidth, mPreviewHeight);
       // 设置预览照片时每秒显示多少帧的最小值和最大值
       parameters.setPreviewFpsRange(mFrameMin, mFrameMax);
       // 设置图片格式
       parameters.setPictureFormat(mImageFormat);
       // 设置JPG照片的质量
       parameters.set("jpeg-quality", mImageQuality);
       // 设置照片的大小
       parameters.setPictureSize(mPictureWidth, mPictureHeight);
       // 通过SurfaceView显示取景画面
       mCamera.setPreviewDisplay(mSurfaceHolder);
       // 开始预览
       mCamera.startPreview();
       azLog.log("AzCamera", "摄像头打开");
     } catch (IOException e) {
       e.printStackTrace();
     }
     isPreview = true;
   }
 }
コード例 #12
0
  @Override
  public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
    Log.e("ok", "surfaceChanged => w=" + i2 + ", h=" + i3);
    // before changing the application orientation, you need to stop the preview, rotate and then
    // start it again
    if (surfaceHolder.getSurface() == null) // check if the surface is ready to receive camera data
    return;

    try {
      mCamera.stopPreview();
    } catch (Exception e) {
      // this will happen when you are trying the camera if it's not running
    }

    // now, recreate the camera preview
    try {

      Camera.Parameters parameters = mCamera.getParameters();
      List<String> focusModes = parameters.getSupportedFocusModes();
      if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
      }
      parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
      mCamera.setParameters(parameters);
      mCamera.setDisplayOrientation(90);
      mCamera.startPreview(mHolder);
    } catch (IOException e) {
      Log.d("ERROR", "Camera error on surfaceChanged " + e.getMessage());
    }
  }
コード例 #13
0
  private void initPreview(int width, int height) {
    if (camera != null && previewHolder.getSurface() != null) {
      try {
        camera.setPreviewDisplay(previewHolder);
      } catch (Throwable t) {

      }

      if (!cameraConfigured) {
        Camera.Parameters parameters = camera.getParameters();
        Camera.Size size = getBestPreviewSize(width, height, parameters);
        Camera.Size pictureSize = getLargestPictureSize(parameters);

        if (size != null && pictureSize != null) {
          if (parameters.getSupportedFocusModes().contains(Camera.Parameters.FOCUS_MODE_AUTO)) {

            // set the focus mode
            parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
          }
          parameters.setPreviewSize(size.width, size.height);
          parameters.setPictureSize(pictureSize.width, pictureSize.height);
          parameters.setPictureFormat(ImageFormat.JPEG);
          camera.setParameters(parameters);
          cameraConfigured = true;
        }
      }
    }
  }
コード例 #14
0
  @SuppressLint("InlinedApi")
  private static void setDesiredCameraParameters(
      final Camera camera, final Camera.Size cameraResolution, final boolean continuousAutoFocus) {
    final Camera.Parameters parameters = camera.getParameters();
    if (parameters == null) return;

    final List<String> supportedFocusModes = parameters.getSupportedFocusModes();
    final String focusMode =
        continuousAutoFocus
            ? findValue(
                supportedFocusModes,
                Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE,
                Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO,
                Camera.Parameters.FOCUS_MODE_AUTO,
                Camera.Parameters.FOCUS_MODE_MACRO)
            : findValue(
                supportedFocusModes,
                Camera.Parameters.FOCUS_MODE_AUTO,
                Camera.Parameters.FOCUS_MODE_MACRO);
    if (focusMode != null) parameters.setFocusMode(focusMode);

    parameters.setPreviewSize(cameraResolution.width, cameraResolution.height);

    camera.setParameters(parameters);
  }
コード例 #15
0
ファイル: AzCameraClass.java プロジェクト: zgljl2012/AzCamera
 @Override
 public void setPreviewHeight(int mPreviewHeight) {
   this.mPreviewHeight = mPreviewHeight;
   Camera.Parameters parameters = mCamera.getParameters();
   // 设置预览照片的大小
   parameters.setPreviewSize(mPreviewWidth, mPreviewHeight);
 }
コード例 #16
0
ファイル: VideoCaptureAndroid.java プロジェクト: hinike/opera
  private int tryStartCapture(int width, int height, int frameRate) {
    if (camera == null) {
      Log.e(TAG, "Camera not initialized %d" + id);
      return -1;
    }

    Log.d(
        TAG,
        "tryStartCapture: "
            + width
            + "x"
            + height
            + ", frameRate: "
            + frameRate
            + ", isCaptureRunning: "
            + isCaptureRunning
            + ", isSurfaceReady: "
            + isSurfaceReady
            + ", isCaptureStarted: "
            + isCaptureStarted);

    if (isCaptureRunning || !isCaptureStarted) {
      return 0;
    }

    CaptureCapabilityAndroid currentCapability = new CaptureCapabilityAndroid();
    currentCapability.width = width;
    currentCapability.height = height;
    currentCapability.maxFPS = frameRate;
    PixelFormat.getPixelFormatInfo(PIXEL_FORMAT, pixelFormat);

    Camera.Parameters parameters = camera.getParameters();
    parameters.setPreviewSize(currentCapability.width, currentCapability.height);
    parameters.setPreviewFormat(PIXEL_FORMAT);
    parameters.setPreviewFrameRate(currentCapability.maxFPS);
    try {
      camera.setParameters(parameters);
    } catch (RuntimeException e) {
      Log.e(TAG, "setParameters failed", e);
      return -1;
    }

    int bufSize = width * height * pixelFormat.bitsPerPixel / 8;
    byte[] buffer = null;
    for (int i = 0; i < numCaptureBuffers; i++) {
      buffer = new byte[bufSize];
      camera.addCallbackBuffer(buffer);
    }
    camera.setPreviewCallbackWithBuffer(this);
    ownsBuffers = true;

    camera.startPreview();
    previewBufferLock.lock();
    expectedFrameSize = bufSize;
    isCaptureRunning = true;
    previewBufferLock.unlock();

    return 0;
  }
コード例 #17
0
  void setDesiredCameraParameters(Camera camera, boolean safeMode) {
    Camera.Parameters parameters = camera.getParameters();

    if (parameters == null) {
      Log.w(
          TAG,
          "Device error: no camera parameters are available. Proceeding without configuration.");
      return;
    }

    Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

    if (safeMode) {
      Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    initializeTorch(parameters, prefs, safeMode);

    String focusMode = null;
    if (prefs.getBoolean(PreferencesActivity.KEY_AUTO_FOCUS, true)) {
      if (safeMode || prefs.getBoolean(PreferencesActivity.KEY_DISABLE_CONTINUOUS_FOCUS, false)) {
        focusMode =
            findSettableValue(
                parameters.getSupportedFocusModes(), Camera.Parameters.FOCUS_MODE_AUTO);
      } else {
        focusMode =
            findSettableValue(
                parameters.getSupportedFocusModes(),
                "continuous-picture", // Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE in 4.0+
                "continuous-video", // Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO in 4.0+
                Camera.Parameters.FOCUS_MODE_AUTO);
      }
    }
    // Maybe selected auto-focus but not available, so fall through here:
    if (!safeMode && focusMode == null) {
      focusMode =
          findSettableValue(
              parameters.getSupportedFocusModes(),
              Camera.Parameters.FOCUS_MODE_MACRO,
              "edof"); // Camera.Parameters.FOCUS_MODE_EDOF in 2.2+
    }
    if (focusMode != null) {
      parameters.setFocusMode(focusMode);
    }

    if (prefs.getBoolean(PreferencesActivity.KEY_INVERT_SCAN, false)) {
      String colorMode =
          findSettableValue(
              parameters.getSupportedColorEffects(), Camera.Parameters.EFFECT_NEGATIVE);
      if (colorMode != null) {
        parameters.setColorEffect(colorMode);
      }
    }

    parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
    camera.setParameters(parameters);
  }
コード例 #18
0
ファイル: Preview.java プロジェクト: CadeLaRen/EagleEye
  // https://code.google.com/p/google-glass-api/issues/detail?id=232
  public void googleGlassXE10WorkAround(Camera mCamera) {
    Camera.Parameters params = mCamera.getParameters();
    params.setPreviewFpsRange(30000, 30000);
    params.setPreviewSize(640, 360);
    mCamera.setParameters(params);

    mCamera.setZoomChangeListener(this);
  }
コード例 #19
0
ファイル: CameraView.java プロジェクト: jose91enrique/ipoki
 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
   // Now that the size is known, set up the camera parameters and begin
   // the preview.
   Camera.Parameters parameters = mCamera.getParameters();
   parameters.setPreviewSize(w, h);
   mCamera.setParameters(parameters);
   mCamera.startPreview();
 }
コード例 #20
0
  private void setCameraParameters() {
    mParameters = mCameraDevice.getParameters();

    //    	mParameters.setPreviewSize(mViewFinderWidth, mViewFinderHeight);
    mParameters.setPreviewSize(320, 240);

    mCameraDevice.setParameters(mParameters);
  }
コード例 #21
0
 /**
  * Sets the camera up to take preview images which are used for both preview and decoding. We
  * detect the preview format here so that buildLuminanceSource() can build an appropriate
  * LuminanceSource subclass. In the future we may want to force YUV420SP as it's the smallest, and
  * the planar Y can be used for barcode scanning without a copy in some cases.
  */
 void setDesiredCameraParameters(Camera camera) {
   Camera.Parameters parameters = camera.getParameters();
   Log.d(TAG, "Setting preview size: " + cameraResolution);
   parameters.setPreviewSize(cameraResolution.x, cameraResolution.y);
   setFlash(parameters);
   setZoom(parameters);
   // setSharpness(parameters);
   camera.setParameters(parameters);
 }
コード例 #22
0
  void setDesiredCameraParameters(OpenCamera camera, boolean safeMode) {

    Camera theCamera = camera.getCamera();
    Camera.Parameters parameters = theCamera.getParameters();

    //    theCamera.setDisplayOrientation(90);//add 这句代码作用是旋转镜头90度,使相机预览方向正确显示

    if (parameters == null) {
      Log.w(
          TAG,
          "Device error: no camera parameters are available. Proceeding without configuration.");
      return;
    }

    Log.i(TAG, "Initial camera parameters: " + parameters.flatten());

    if (safeMode) {
      Log.w(TAG, "In camera config safe mode -- most settings will not be honored");
    }

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    initializeTorch(parameters, prefs, safeMode);

    CameraConfigurationUtils.setFocus(parameters, true, true, safeMode);

    if (!safeMode) {
      CameraConfigurationUtils.setBarcodeSceneMode(parameters);
      CameraConfigurationUtils.setVideoStabilization(parameters);
      CameraConfigurationUtils.setFocusArea(parameters);
      CameraConfigurationUtils.setMetering(parameters);
    }

    parameters.setPreviewSize(bestPreviewSize.x, bestPreviewSize.y);

    theCamera.setParameters(parameters);

    theCamera.setDisplayOrientation(cwRotationFromDisplayToCamera);

    Camera.Parameters afterParameters = theCamera.getParameters();
    Camera.Size afterSize = afterParameters.getPreviewSize();
    if (afterSize != null
        && (bestPreviewSize.x != afterSize.width || bestPreviewSize.y != afterSize.height)) {
      Log.w(
          TAG,
          "Camera said it supported preview size "
              + bestPreviewSize.x
              + 'x'
              + bestPreviewSize.y
              + ", but after setting it, preview size is "
              + afterSize.width
              + 'x'
              + afterSize.height);
      bestPreviewSize.x = afterSize.width;
      bestPreviewSize.y = afterSize.height;
    }
  }
コード例 #23
0
 void setDesiredCameraParameters(Camera paramCamera) {
   Camera.Parameters localParameters = paramCamera.getParameters();
   Log.d(TAG, "Setting preview size: " + this.cameraResolution);
   localParameters.setPreviewSize(this.cameraResolution.x, this.cameraResolution.y);
   setFlash(localParameters);
   setZoom(localParameters);
   setDisplayOrientation(paramCamera, 90);
   paramCamera.setParameters(localParameters);
 }
コード例 #24
0
 @Override
 public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
   Camera.Parameters parameters;
   parameters = mCamera.getParameters();
   // Set the camera preview size
   parameters.setPreviewSize(PreviewSizeWidth, PreviewSizeHeight);
   imageFormat = parameters.getPreviewFormat();
   mCamera.setParameters(parameters);
   mCamera.startPreview();
 }
コード例 #25
0
ファイル: Preview.java プロジェクト: trucomanx/MonoVisionTest
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    if (mCamera != null) {
      Camera.Parameters parameters = mCamera.getParameters();
      parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
      requestLayout();

      mCamera.setParameters(parameters);
      mCamera.startPreview();
    }
  }
コード例 #26
0
  // Called by native code.  Returns true if capturer is started.
  //
  // Note that this actually opens the camera, which can be a slow operation and
  // thus might be done on a background thread, but ViE API needs a
  // synchronous success return value so we can't do that.
  private synchronized boolean startCapture(int width, int height, int min_mfps, int max_mfps) {
    Log.d(TAG, "startCapture: " + width + "x" + height + "@" + min_mfps + ":" + max_mfps);
    Throwable error = null;
    try {
      camera = Camera.open(id);

      localPreview = ViERenderer.GetLocalRenderer();
      if (localPreview != null) {
        localPreview.addCallback(this);
        if (localPreview.getSurface() != null && localPreview.getSurface().isValid()) {
          camera.setPreviewDisplay(localPreview);
        }
      } else {
        // No local renderer (we only care about onPreviewFrame() buffers, not a
        // directly-displayed UI element).  Camera won't capture without
        // setPreview{Texture,Display}, so we create a dummy SurfaceTexture and
        // hand it over to Camera, but never listen for frame-ready callbacks,
        // and never call updateTexImage on it.
        try {
          // "42" because http://goo.gl/KaEn8
          dummySurfaceTexture = new SurfaceTexture(42);
          camera.setPreviewTexture(dummySurfaceTexture);
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      Camera.Parameters parameters = camera.getParameters();
      Log.d(TAG, "isVideoStabilizationSupported: " + parameters.isVideoStabilizationSupported());
      if (parameters.isVideoStabilizationSupported()) {
        parameters.setVideoStabilization(true);
      }
      parameters.setPreviewSize(width, height);
      parameters.setPreviewFpsRange(min_mfps, max_mfps);
      int format = ImageFormat.NV21;
      parameters.setPreviewFormat(format);
      camera.setParameters(parameters);
      int bufSize = width * height * ImageFormat.getBitsPerPixel(format) / 8;
      for (int i = 0; i < numCaptureBuffers; i++) {
        camera.addCallbackBuffer(new byte[bufSize]);
      }
      camera.setPreviewCallbackWithBuffer(this);
      camera.startPreview();
      return true;
    } catch (IOException e) {
      error = e;
    } catch (RuntimeException e) {
      error = e;
    }
    Log.e(TAG, "startCapture failed", error);
    if (camera != null) {
      stopCapture();
    }
    return false;
  }
コード例 #27
0
ファイル: CameraActivity.java プロジェクト: ludomuse/Ludomuse
        public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
          Camera.Parameters parameters = camera.getParameters();
          Camera.Size size = getBestPreviewSize(width, height, parameters);

          if (size != null) {
            parameters.setPreviewSize(size.width, size.height);
            camera.setParameters(parameters);
            camera.startPreview();
            inPreview = true;
          }
        }
コード例 #28
0
ファイル: CameraActivity.java プロジェクト: KiLMaN/Master-RA
    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
      Camera.Parameters parameters = mCamera.getParameters();
      List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes();

      // You need to choose the most appropriate previewSize for your app
      Camera.Size previewSize = previewSizes.get(2); // .... select one of previewSizes here

      parameters.setPreviewSize(previewSize.width, previewSize.height);
      mCamera.setParameters(parameters);
      mCamera.startPreview();
    }
コード例 #29
0
ファイル: CameraPreview.java プロジェクト: vas85/QeoProject
 @Override
 public void surfaceChanged(SurfaceHolder arg0, int format, int width, int height) {
   if (mCamera != null) {
     Camera.Parameters parameters = mCamera.getParameters();
     parameters.setPreviewSize(
         mSupportedPreviewSizes.get(0).width, mSupportedPreviewSizes.get(0).height);
     requestLayout();
     mCamera.setParameters(parameters);
     mCamera.startPreview();
   }
 }
コード例 #30
0
 /** {@inheritDoc} */
 @Override
 public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
   Camera.Parameters parameters = camera.getParameters();
   parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
   Camera.Size size = getSmallestPreviewSize(width, height, parameters);
   if (size != null) {
     parameters.setPreviewSize(size.width, size.height);
     Log.d(TAG, "Using width=" + size.width + " height=" + size.height);
   }
   camera.setParameters(parameters);
   camera.startPreview();
 }