Java Code Examples for android.hardware.Camera.Size.equals()

The following are Jave code examples for showing how to use equals() of the android.hardware.Camera.Size class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AndroidRosJava   File: CompressedImagePublisher.java   View Source Code Vote up 5 votes
@Override
public void onNewRawImage(byte[] data, Size size) {
  Preconditions.checkNotNull(data);
  Preconditions.checkNotNull(size);
  if (data != rawImageBuffer || !size.equals(rawImageSize)) {
    rawImageBuffer = data;
    rawImageSize = size;
    yuvImage = new YuvImage(rawImageBuffer, ImageFormat.NV21, size.width, size.height, null);
    rect = new Rect(0, 0, size.width, size.height);
  }

  Time currentTime = connectedNode.getCurrentTime();
  String frameId = "camera";

  sensor_msgs.CompressedImage image = imagePublisher.newMessage();
  image.setFormat("jpeg");
  image.getHeader().setStamp(currentTime);
  image.getHeader().setFrameId(frameId);

  Preconditions.checkState(yuvImage.compressToJpeg(rect, 20, stream));
  image.setData(stream.buffer().copy());
  stream.buffer().clear();

  imagePublisher.publish(image);

  sensor_msgs.CameraInfo cameraInfo = cameraInfoPublisher.newMessage();
  cameraInfo.getHeader().setStamp(currentTime);
  cameraInfo.getHeader().setFrameId(frameId);

  cameraInfo.setWidth(size.width);
  cameraInfo.setHeight(size.height);
  cameraInfoPublisher.publish(cameraInfo);
}
 
Example 2
Project: WiCamera3D   File: VideoSurfaceView2D.java   View Source Code Vote up 5 votes
@Override
public void setPreviewSize() {
	try {
		if (cameras != null) {

			// camera_parameters
			// .setPreviewSize(WiCameraActivity.screenWidth
			// + WiCameraActivity.sbarh,
			// WiCameraActivity.screenHeight);
			List<Size> sizes = camera_parameters.getSupportedPreviewSizes();
			int picsize = StoredData.getInt(StoredData.M_PICTURESIZE, 0);
			Size optimalSize = Util.getOptimalPreviewSize(
					(Activity) m_context, sizes,
					(double) CAMERA_PICSIZE[picsize][0]
							/ CAMERA_PICSIZE[picsize][1]);
			Size original = camera_parameters.getPreviewSize();
			if (!original.equals(optimalSize)) {
				System.out.println("预览大小:宽=" + optimalSize.width + "高="
						+ optimalSize.height);
				camera_parameters.setPreviewSize(optimalSize.width,
						optimalSize.height);
				cameras.setParameters(camera_parameters);
			}

			cameras.setParameters(camera_parameters);
		}
	} catch (Exception e) {
		// TODO: handle exception
		e.printStackTrace();
	}

}
 
Example 3
Project: WiCamera3D   File: VideoSurfaceView.java   View Source Code Vote up 5 votes
@Override
public void setPreviewSize() {
	try {
		if (cameras != null) {

			// camera_parameters
			// .setPreviewSize(WiCameraActivity.screenWidth
			// + WiCameraActivity.sbarh,
			// WiCameraActivity.screenHeight);
			List<Size> sizes = camera_parameters.getSupportedPreviewSizes();
			int picsize = StoredData.getInt(StoredData.M_PICTURESIZE, 0);
			Size optimalSize = Util.getOptimalPreviewSize(
					(Activity) m_context, sizes,
					(double) CAMERA_PICSIZE[picsize][0]
							/ CAMERA_PICSIZE[picsize][1]);
			Size original = camera_parameters.getPreviewSize();
			if (!original.equals(optimalSize)) {
				System.out.println("预览大小:宽=" + optimalSize.width + "高="
						+ optimalSize.height);
				camera_parameters.setPreviewSize(optimalSize.width,
						optimalSize.height);
				cameras.setParameters(camera_parameters);
			}

			cameras.setParameters(camera_parameters);
		}
	} catch (Exception e) {
		// TODO: handle exception
		e.printStackTrace();
	}

}
 
Example 4
Project: nexus-camera   File: VideoModule.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
private void setCameraParameters() {
    mParameters.setPreviewSize(mDesiredPreviewWidth, mDesiredPreviewHeight);
    int[] fpsRange = CameraUtil.getMaxPreviewFpsRange(mParameters);
    if (fpsRange.length > 0) {
        mParameters.setPreviewFpsRange(
                fpsRange[Parameters.PREVIEW_FPS_MIN_INDEX],
                fpsRange[Parameters.PREVIEW_FPS_MAX_INDEX]);
    } else {
        mParameters.setPreviewFrameRate(mProfile.videoFrameRate);
    }

    forceFlashOffIfSupported(!mUI.isVisible());

    // Set white balance parameter.
    String whiteBalance = mPreferences.getString(
            CameraSettings.KEY_WHITE_BALANCE,
            mActivity.getString(R.string.pref_camera_whitebalance_default));
    if (isSupported(whiteBalance,
            mParameters.getSupportedWhiteBalance())) {
        mParameters.setWhiteBalance(whiteBalance);
    } else {
        whiteBalance = mParameters.getWhiteBalance();
        if (whiteBalance == null) {
            whiteBalance = Parameters.WHITE_BALANCE_AUTO;
        }
    }

    // Set zoom.
    if (mParameters.isZoomSupported()) {
        mParameters.setZoom(mZoomValue);
    }

    // Set continuous autofocus.
    List<String> supportedFocus = mParameters.getSupportedFocusModes();
    if (isSupported(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO, supportedFocus)) {
        mParameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }

    mParameters.set(CameraUtil.RECORDING_HINT, CameraUtil.TRUE);

    // Enable video stabilization. Convenience methods not available in API
    // level <= 14
    String vstabSupported = mParameters.get("video-stabilization-supported");
    if ("true".equals(vstabSupported)) {
        mParameters.set("video-stabilization", "true");
    }

    // Set picture size.
    // The logic here is different from the logic in still-mode camera.
    // There we determine the preview size based on the picture size, but
    // here we determine the picture size based on the preview size.
    List<Size> supported = mParameters.getSupportedPictureSizes();
    Size optimalSize = CameraUtil.getOptimalVideoSnapshotPictureSize(supported,
            (double) mDesiredPreviewWidth / mDesiredPreviewHeight);
    Size original = mParameters.getPictureSize();
    if (!original.equals(optimalSize)) {
        mParameters.setPictureSize(optimalSize.width, optimalSize.height);
    }
    Log.v(TAG, "Video snapshot size is " + optimalSize.width + "x" +
            optimalSize.height);

    // Set JPEG quality.
    int jpegQuality = CameraProfile.getJpegEncodingQualityParameter(mCameraId,
            CameraProfile.QUALITY_HIGH);
    mParameters.setJpegQuality(jpegQuality);

    mCameraDevice.setParameters(mParameters);
    // Keep preview size up to date.
    mParameters = mCameraDevice.getParameters();

    // Update UI based on the new parameters.
    mUI.updateOnScreenIndicators(mParameters, mPreferences);
}