public void setCameraDisplaySetting() {

    // //Set Orentation
    if (!devicearraydata[2].equals("BYPASS")) { // --> For Camera Orentation Support
      cam.setDisplayOrientation(Integer.parseInt(devicearraydata[2]));
    }
    // //Set Camera Preview
    // Parameters param = cam.getParameters();
    // param.setPreviewSize(Integer.parseInt(devicearraydata[4]),
    // Integer.parseInt(devicearraydata[3]));
    try {
      // cam.setParameters(param);
      setPictureSizeOfScreenAndPreviewsize();
    } catch (Exception e) {
      PrintLog.print(activity, "Can't setPreviewSize");
      Parameters param = cam.getParameters();
      param.setPreviewSize(480, 640);
      cam.setParameters(param);
      PrintLog.print(activity, "set lowest PreviewSize 480x640");
    }
    PrintLog.print(activity.getApplicationContext(), Deviceinfo.BUILD_MODEL);
    PrintLog.print(
        activity.getApplicationContext(), Deviceinfo.getDeviceScreenOrentation(activity));
    PrintLog.print(
        activity.getApplicationContext(),
        "W"
            + Deviceinfo.getDeviceScreenSize(activity)[0]
            + "|H"
            + Deviceinfo.getDeviceScreenSize(activity)[1]
            + "|A"
            + Deviceinfo.getStatusBarHeight(activity));
  }
  @TargetApi(Build.VERSION_CODES.HONEYCOMB)
  @Override
  protected void onResume() {
    super.onResume();
    Log.i(TAG, "onResume");
    currentCameraId = Camera.CameraInfo.CAMERA_FACING_FRONT;
    camera = Camera.open(currentCameraId);
    int pictureHeight = camera.getParameters().getPictureSize().height;
    int pictureWidth = camera.getParameters().getPictureSize().width;
    FrameLayout surfWrap = (FrameLayout) findViewById(R.id.surface_wrapper);
    surfWrap.setLayoutParams(new FrameLayout.LayoutParams(pictureHeight, pictureWidth));

    Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();

    int orientation = display.getRotation();
    Log.i("Rotation", String.valueOf(orientation));
    if (orientation == Surface.ROTATION_90) {
      // TODO: add logic for landscape mode here
      Log.i("Rotation", "Landscape mode");
      displayRotation = 0;
    } else if (orientation == Surface.ROTATION_270) {

      displayRotation = 270;
    } else {
      Log.i("Rotation", "Portrait mode");
      displayRotation = 90;
    }
  }
Example #3
0
  @Override
  protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int width = resolveSize(getSuggestedMinimumWidth(), widthMeasureSpec);
    final int height = resolveSize(getSuggestedMinimumHeight(), heightMeasureSpec);
    setMeasuredDimension(width, height);

    if (width > 0 && height > 0) {
      if (camera != null) {
        Camera.Size newSize = null;

        try {
          if (getHost().getRecordingHint() != CameraHost.RecordingHint.STILL_ONLY) {
            // Camera.Size deviceHint=
            // host.getDeviceProfile()
            // .getPreferredPreviewSizeForVideo(getDisplayOrientation(),
            // width,
            // height,
            // camera.getParameters());

            newSize =
                getHost()
                    .getPreferredPreviewSizeForVideo(
                        getDisplayOrientation(), width, height, camera.getParameters(), null);

            // if (newSize != null) {
            // android.util.Log.wtf("CameraView",
            // String.format("getPreferredPreviewSizeForVideo: %d x %d",
            // newSize.width,
            // newSize.height));
            // }
          }

          if (newSize == null || newSize.width * newSize.height < 65536) {
            newSize =
                getHost()
                    .getPreviewSize(getDisplayOrientation(), width, height, camera.getParameters());
          }
        } catch (Exception e) {
          android.util.Log.e(
              getClass().getSimpleName(), "Could not work with camera parameters?", e);
          // TODO get this out to library clients
        }

        if (newSize != null) {
          if (previewSize == null) {
            previewSize = newSize;
          } else if (previewSize.width != newSize.width || previewSize.height != newSize.height) {
            if (inPreview) {
              stopPreview();
            }

            previewSize = newSize;
            initPreview(width, height, false);
          }
        }
      }
    }
  }
  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;
    }
  }
Example #5
0
 public synchronized void zoomOut() {
   if (mCamera != null
       && mCamera.getParameters().isZoomSupported()
       && mCamera.getParameters().isSmoothZoomSupported()
       && !zooming) {
     int zoomvalue = mCamera.getParameters().getZoom() - zoomOffset;
     if (zoomvalue >= 0) {
       mCamera.startSmoothZoom(zoomvalue);
     }
   }
 }
  private static boolean getTorchEnabled(final Camera camera) {
    final Camera.Parameters parameters = camera.getParameters();
    if (parameters != null) {
      final String flashMode = camera.getParameters().getFlashMode();
      return flashMode != null
          && (Camera.Parameters.FLASH_MODE_ON.equals(flashMode)
              || Camera.Parameters.FLASH_MODE_TORCH.equals(flashMode));
    }

    return false;
  }
Example #7
0
  /** 焦点放小 */
  public void zoomOut() {
    if (camera != null && camera.getParameters().isZoomSupported()) {

      Camera.Parameters parameters = camera.getParameters();
      if (parameters.getZoom() <= 0) {
        return;
      }

      parameters.setZoom(parameters.getZoom() - 1);
      camera.setParameters(parameters);
    }
  }
Example #8
0
  @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());
  }
 boolean getTorchState(Camera camera) {
   if (camera != null) {
     Camera.Parameters parameters = camera.getParameters();
     if (parameters != null) {
       String flashMode = camera.getParameters().getFlashMode();
       return flashMode != null
           && (Camera.Parameters.FLASH_MODE_ON.equals(flashMode)
               || Camera.Parameters.FLASH_MODE_TORCH.equals(flashMode));
     }
   }
   return false;
 }
Example #10
0
  /*
   * 缩放
   *
   * @param scale
   */
  public void setCameraZoom(int scale) {
    if (camera != null
        && camera.getParameters().isZoomSupported()
        && scale <= camera.getParameters().getMaxZoom()
        && scale >= 0) {

      Camera.Parameters parameters = camera.getParameters();

      parameters.setZoom(scale);
      camera.setParameters(parameters);
    }
  }
Example #11
0
  /** 焦点放大 */
  public void zoomIn() {
    if (camera != null && camera.getParameters().isZoomSupported()) {

      Camera.Parameters parameters = camera.getParameters();
      if (parameters.getZoom() >= parameters.getMaxZoom()) {
        return;
      }

      parameters.setZoom(parameters.getZoom() + 1);
      camera.setParameters(parameters);
    }
  }
  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;
  }
Example #13
0
  public synchronized void setupCamera(int width, int height) {
    if (mCamera != null) {
      Log.i(TAG, "Setup Camera - " + width + "x" + height);
      Camera.Parameters params = mCamera.getParameters();
      List<Camera.Size> sizes = params.getSupportedPreviewSizes();
      mFrameWidth = width;
      mFrameHeight = height;

      // selecting optimal camera preview size
      {
        int minDiff = Integer.MAX_VALUE;
        for (Camera.Size size : sizes) {
          if (Math.abs(size.height - height) < minDiff) {
            mFrameWidth = size.width;
            mFrameHeight = size.height;
            minDiff = Math.abs(size.height - height);
          }
        }
      }

      params.setPreviewSize(getFrameWidth(), getFrameHeight());

      List<String> FocusModes = params.getSupportedFocusModes();
      if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
        params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
      }

      mCamera.setParameters(params);

      /* Now allocate the buffer */
      params = mCamera.getParameters();
      int size = params.getPreviewSize().width * params.getPreviewSize().height;
      size = size * ImageFormat.getBitsPerPixel(params.getPreviewFormat()) / 8;
      mBuffer = new byte[size];
      /* The buffer where the current frame will be copied */
      mFrame = new byte[size];
      mCamera.addCallbackBuffer(mBuffer);

      /* Notify that the preview is about to be started and deliver preview size */
      onPreviewStarted(params.getPreviewSize().width, params.getPreviewSize().height);

      try {
        setPreview();
      } catch (IOException e) {
        Log.e(TAG, "mCamera.setPreviewDisplay/setPreviewTexture fails: " + e);
      }

      /* Now we can start a preview */
      mCamera.startPreview();
    }
  }
Example #14
0
  /** Handles camera opening */
  private void openCamera(int which) {
    if (mCamera != null) {
      mCamera.stopPreview();
      mCamera.release();
      mCamera = null;
    }

    if (mCameraId >= 0) {
      Camera.getCameraInfo(mCameraId, mCameraInfo);
      if (which == FRONT) mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
      else mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);

      params = mCamera.getParameters();
      params.setRotation(0);

      /** set focus mode */
      List<String> FocusModes = params.getSupportedFocusModes();
      if (FocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
        params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
      }

      mCamera.setParameters(params);
      try {
        if (mSurfaceTexture != null) {
          mCamera.setPreviewTexture(mSurfaceTexture);
          mCamera.startPreview();
        }
      } catch (Exception ex) {
      }
    }

    if (mCamera == null || mSharedData == null) {
      return;
    }

    int orientation = mCameraInfo.orientation + rot_angle;

    Matrix.setRotateM(mSharedData.mOrientationM, 0, orientation, 0f, 0f, 1f);

    Camera.Size size = mCamera.getParameters().getPreviewSize();
    if (orientation % 90 == 0) {
      int w = size.width;
      size.width = size.height;
      size.height = w;
    }

    mSharedData.mAspectRatioPreview[0] = (float) Math.min(size.width, size.height) / size.width;
    mSharedData.mAspectRatioPreview[1] = (float) Math.min(size.width, size.height) / size.height;
  }
Example #15
0
  @SuppressLint("NewApi") // CameraInfo
  @SuppressWarnings("deprecation") // setPreviewFrameRate
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

    if (camera != null) {

      String camResolution =
          PreferenceManager.getDefaultSharedPreferences(getContext())
              .getString(
                  "pref_cameraResolution",
                  getResources().getString(R.string.pref_defaultValue_cameraResolution));
      String[] dims = camResolution.split("x", 2);
      Camera.Parameters parameters = camera.getParameters();
      parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1]));
      parameters.setPreviewFrameRate(30);
      camera.setParameters(parameters);

      parameters = camera.getParameters();
      int capWidth = parameters.getPreviewSize().width;
      int capHeight = parameters.getPreviewSize().height;
      int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat
      PixelFormat pixelinfo = new PixelFormat();
      PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo);
      int cameraIndex = 0;
      boolean frontFacing = false;
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        cameraIndex =
            Integer.parseInt(
                PreferenceManager.getDefaultSharedPreferences(getContext())
                    .getString("pref_cameraIndex", "0"));
        Camera.getCameraInfo(cameraIndex, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) frontFacing = true;
      }

      int bufSize =
          capWidth
              * capHeight
              * pixelinfo.bitsPerPixel
              / 8; // For the default NV21 format, bitsPerPixel = 12.

      for (int i = 0; i < 5; i++) camera.addCallbackBuffer(new byte[bufSize]);

      camera.startPreview();

      nftBookActivity.nativeVideoInit(capWidth, capHeight, cameraIndex, frontFacing);
    }
  }
Example #16
0
  /**
   * Opens the camera driver and initializes the hardware parameters.
   *
   * @param holder The surface object which the camera will draw preview frames into.
   * @throws IOException Indicates the camera driver failed to open.
   */
  public synchronized void openDriver(SurfaceHolder holder) throws IOException {
    Camera theCamera = camera;
    if (theCamera == null) {
      // 获取手机背面的摄像头
      theCamera = OpenCameraInterface.open();
      if (theCamera == null) {
        throw new IOException();
      }
      camera = theCamera;
    }

    // 设置摄像头预览view
    theCamera.setPreviewDisplay(holder);

    if (!initialized) {
      initialized = true;
      configManager.initFromCameraParameters(theCamera);
      if (requestedFramingRectWidth > 0 && requestedFramingRectHeight > 0) {
        setManualFramingRect(requestedFramingRectWidth, requestedFramingRectHeight);
        requestedFramingRectWidth = 0;
        requestedFramingRectHeight = 0;
      }
    }

    Camera.Parameters parameters = theCamera.getParameters();
    String parametersFlattened = parameters == null ? null : parameters.flatten(); // Save
    // these,
    // temporarily
    try {
      configManager.setDesiredCameraParameters(theCamera, false);
    } catch (RuntimeException re) {
      // Driver failed
      Log.w(TAG, "Camera rejected parameters. Setting only minimal safe-mode parameters");
      Log.i(TAG, "Resetting to saved camera params: " + parametersFlattened);
      // Reset:
      if (parametersFlattened != null) {
        parameters = theCamera.getParameters();
        parameters.unflatten(parametersFlattened);
        try {
          theCamera.setParameters(parameters);
          configManager.setDesiredCameraParameters(theCamera, true);
        } catch (RuntimeException re2) {
          // Well, darn. Give up
          Log.w(TAG, "Camera rejected even safe-mode parameters! No configuration");
        }
      }
    }
  }
Example #17
0
 @Override
 public void setPreviewHeight(int mPreviewHeight) {
   this.mPreviewHeight = mPreviewHeight;
   Camera.Parameters parameters = mCamera.getParameters();
   // 设置预览照片的大小
   parameters.setPreviewSize(mPreviewWidth, mPreviewHeight);
 }
Example #18
0
 /** 给摄像头设置好一系列相关参数,并开始预览 */
 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;
   }
 }
  private void checkRearCamera() {
    Camera camera = null;
    try {
      camera = Camera.open();
      if (camera != null) {
        assertAvailable(PackageManager.FEATURE_CAMERA);

        Camera.Parameters params = camera.getParameters();
        if (params.getSupportedFocusModes().contains(Parameters.FOCUS_MODE_AUTO)) {
          assertAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS);
        } else {
          assertNotAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS);
        }

        if (params.getFlashMode() != null) {
          assertAvailable(PackageManager.FEATURE_CAMERA_FLASH);
        } else {
          assertNotAvailable(PackageManager.FEATURE_CAMERA_FLASH);
        }
      } else {
        assertNotAvailable(PackageManager.FEATURE_CAMERA);
        assertNotAvailable(PackageManager.FEATURE_CAMERA_AUTOFOCUS);
        assertNotAvailable(PackageManager.FEATURE_CAMERA_FLASH);
      }
    } finally {
      if (camera != null) {
        camera.release();
      }
    }
  }
  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());
    }
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Hide the window title.
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().setFormat(PixelFormat.UNKNOWN);
    setContentView(R.layout.main);

    // Create an instance of Camera
    mCamera = getCameraInstance();
    Camera.Parameters mParameters = mCamera.getParameters();
    mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_AUTO);
    // mParameters.setFlashMode(Camera.Parameters.FLASH_MODE_ON);
    mCamera.setParameters(mParameters);

    // Create our Preview view and set it as the content of our activity.
    mPreview = new Preview(this, mCamera);
    FrameLayout preview = (FrameLayout) findViewById(R.id.preview);
    preview.addView(mPreview);

    // Create our Overlay
    mOverlay = new Overlay(this);
    preview.addView(mOverlay);
    mPreview.setOverlay(mOverlay);

    // Setting buttons
    buttonProc = (Button) findViewById(R.id.buttonProc);
    buttonBinImage = (Button) findViewById(R.id.buttonBinaryImage);
    buttonReset = (Button) findViewById(R.id.buttonReset);
    buttonProc.setOnClickListener(snapAndProcess());
    buttonBinImage.setOnClickListener(switchBinaryImage());
    buttonReset.setOnClickListener(reset());
  }
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    if (mHolder.getSurface() == null) {
      return;
    }

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

    if (mSupportedPreviewSizes != null) {
      mPreviewSize = getOptimalPreviewSize(mSupportedPreviewSizes, w, h);
    }

    // start preview with new settings
    try {

      mCamera.setPreviewDisplay(mHolder);

      Parameters params = mCamera.getParameters();
      // params.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
      params.setPreviewSize(
          mSupportedPreviewSizes.get(0).width, mSupportedPreviewSizes.get(0).height);
      mCamera.setParameters(params);
      mCamera.startPreview();

      Log.d(TAG, "Preview Size: " + mPreviewSize.width + "X" + mPreviewSize.height);

    } catch (Exception e) {
      Log.d(TAG, "Error starting camera preview: " + e.getMessage());
    }
  }
Example #23
0
 public void onPreviewFrame(byte[] data, Camera camera) {
   Camera.Parameters parameters = camera.getParameters();
   width = parameters.getPreviewSize().width;
   height = parameters.getPreviewSize().height;
   yuvImage = new YuvImage(data, ImageFormat.NV21, width, height, null);
   looped += 1;
 }
  public void setSurfaceLayoutToFullScreenNotincludeActionbar(SurfaceView sufview) {
    double per_of_apect;
    int w = Deviceinfo.getDeviceScreenSize(activity)[0],
        h = Deviceinfo.getDeviceScreenSize(activity)[1];
    if (Deviceinfo.getDeviceScreenSize(activity)[0] == 1280
            && Deviceinfo.getDeviceScreenSize(activity)[1] == 800
        || Deviceinfo.getDeviceScreenSize(activity)[1] == 1280
            && Deviceinfo.getDeviceScreenSize(activity)[0] == 800) {
      per_of_apect =
          (((Deviceinfo.getDeviceScreenSize(activity)[1] - Deviceinfo.getStatusBarHeight(activity))
                      * 100.0)
                  / Deviceinfo.getDeviceScreenSize(activity)[1])
              / 100;
      w = (int) ((cam.getParameters().getPreviewSize().height * 2) * (per_of_apect));
      h = Deviceinfo.getDeviceScreenSize(activity)[1] - Deviceinfo.getStatusBarHeight(activity);
    }
    if (Deviceinfo.getDeviceScreenSize(activity)[1] == 800
            && Deviceinfo.getDeviceScreenSize(activity)[0] == 480
        || Deviceinfo.getDeviceScreenSize(activity)[0] == 800
            && Deviceinfo.getDeviceScreenSize(activity)[1] == 480) {
      w = 600;
      h = 800;
    } else if (Deviceinfo.getDeviceScreenSize(activity)[1] == 800
            && Deviceinfo.getDeviceScreenSize(activity)[0] == 1232
        || Deviceinfo.getDeviceScreenSize(activity)[0] == 800
            && Deviceinfo.getDeviceScreenSize(activity)[1] == 1232) {
      w = 924;
      h = 1232;
    }

    sufview.setLayoutParams(new ViewGroup.LayoutParams(w, h));
  }
 public void offLight() {
   if (camera != null) {
     Camera.Parameters parameter = camera.getParameters();
     parameter.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
     camera.setParameters(parameter);
   }
 }
  @Override
  public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters params = camera.getParameters();
    int w = params.getPreviewSize().width;
    int h = params.getPreviewSize().height;
    int format = params.getPreviewFormat();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    YuvImage image = new YuvImage(data, format, w, h, null);
    Rect area = new Rect(0, 0, w, h);

    long start = System.currentTimeMillis();
    image.compressToJpeg(area, imageQuality, out);
    long end = System.currentTimeMillis();

    long pingTime = ServerConnector.getInstance().getPingTime() + (end - start);
    if (pingTime > 50 && imageQuality > 25) {
      imageQuality--;
    } else if (pingTime < 50 && imageQuality < 100) {
      imageQuality++;
    }

    Log.i("image", "" + imageQuality);

    ServerConnector.getInstance().pushImage(out.toByteArray());
  }
  public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);

    int result = mScanner.scanImage(barcode);

    if (result != 0) {
      mCamera.cancelAutoFocus();
      mCamera.setPreviewCallback(null);
      mCamera.stopPreview();
      mPreviewing = false;
      SymbolSet syms = mScanner.getResults();
      for (Symbol sym : syms) {
        String symData = sym.getData();
        if (!TextUtils.isEmpty(symData)) {
          Intent dataIntent = new Intent();
          dataIntent.putExtra(SCAN_RESULT, symData);
          dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
          setResult(Activity.RESULT_OK, dataIntent);
          finish();
          break;
        }
      }
    }
  }
Example #28
0
  // Called when holder has changed
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

    Camera.Parameters parameters = camera.getParameters();
    List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
      Log.d("camera", "focus_mode_auto");
      parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    } else {
      Log.d("camera", "focus_mode_macro");
      parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_MACRO);
    }
    Log.d("camera", "orientation: " + getResources().getConfiguration().orientation);
    int orientation = getResources().getConfiguration().orientation;
    switch (orientation) {
      case Surface.ROTATION_0:
        Log.d("camera", "ROTATION_0");
        camera.setDisplayOrientation(180);
        break;
      case Surface.ROTATION_90:
        Log.d("camera", "ROTATION_90");
        camera.setDisplayOrientation(90);
        break;
      case Surface.ROTATION_180:
        Log.d("camera", "ROTATION_180");
        camera.setDisplayOrientation(0);
        break;
      case Surface.ROTATION_270:
        Log.d("camera", "ROTATION_270");
        camera.setDisplayOrientation(270);
        break;
    }

    camera.setParameters(parameters);
    camera.startPreview();
  }
 public AutoFocusManager(Context context, Camera camera) {
   this.camera = camera;
   String currentFocusMode = camera.getParameters().getFocusMode();
   useAutoFocus = FOCUS_MODES_CALLING_AF.contains(currentFocusMode);
   Log.i(TAG, "Current focus mode '" + currentFocusMode + "'; use auto focus? " + useAutoFocus);
   start();
 }
Example #30
0
 public void setCamera(Camera camera) {
   mCamera = camera;
   if (mCamera != null) {
     mSupportedPreviewSizes = mCamera.getParameters().getSupportedPreviewSizes();
     requestLayout();
   }
 }