• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cordova-plugin-camera-preview/cordova-plugin-camera-preview: Cordova plugin that ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

cordova-plugin-camera-preview/cordova-plugin-camera-preview

开源软件地址:

https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview

开源编程语言:

Java 51.2%

开源软件介绍:

Cordova Plugin Camera Preview

NPM Version NPM Downloads

Cordova plugin that allows camera interaction from Javascript and HTML

Releases are being kept up to date when appropriate. However, this plugin is under constant development. As such it is recommended to use master to always have the latest fixes & features.

PR's are greatly appreciated.

Features

  • Start a camera preview from HTML code
  • Take Photos and Snapshots
  • Maintain HTML interactivity
  • Drag the preview box
  • Set camera color effect
  • Send the preview box to back of the HTML content
  • Set a custom position for the camera preview box
  • Set a custom size for the preview box
  • Set a custom alpha for the preview box
  • Set the focus mode, zoom, color effects, exposure mode, white balance mode and exposure compensation
  • Tap to focus
  • Record Videos

Installation

Use any one of the installation methods listed below depending on which framework you use.

To install the master version with latest fixes and features

cordova plugin add https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git

ionic cordova plugin add https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git

meteor add cordova:cordova-plugin-camera-preview@https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git#[latest_commit_id]

<plugin spec="https://github.com/cordova-plugin-camera-preview/cordova-plugin-camera-preview.git" source="git" />

or if you want to use the last released version on npm

cordova plugin add cordova-plugin-camera-preview

ionic cordova plugin add cordova-plugin-camera-preview

meteor add cordova:[email protected]

<gap:plugin name="cordova-plugin-camera-preview" />

iOS Quirks

  1. It is not possible to use your computers webcam during testing in the simulator, you must device test.
  2. If you are developing for iOS 10+ you must also add the following to your config.xml
<config-file platform="ios" target="*-Info.plist" parent="NSCameraUsageDescription" overwrite="true">
  <string>Allow the app to use your camera</string>
</config-file>

<!-- or for Phonegap -->

<gap:config-file platform="ios" target="*-Info.plist" parent="NSCameraUsageDescription" overwrite="true">
  <string>Allow the app to use your camera</string>
</gap:config-file>

Android Quirks

  1. When using the plugin for older devices, the camera preview will take the focus inside the app once initialized. In order to prevent the app from closing when a user presses the back button, the event for the camera view is disabled. If you still want the user to navigate, you can add a listener for the back event for the preview (see onBackButton)

Methods

startCamera(options, [successCallback, errorCallback])

Starts the camera preview instance.

Options: All options stated are optional and will default to values here

  • x - Defaults to 0
  • y - Defaults to 0
  • width - Defaults to window.screen.width
  • height - Defaults to window.screen.height
  • camera - See CAMERA_DIRECTION - Defaults to front camera
  • toBack - Defaults to false - Set to true if you want your html in front of your preview
  • tapPhoto - Defaults to true - Does not work if toBack is set to false in which case you use the takePicture method
  • tapFocus - Defaults to false - Allows the user to tap to focus, when the view is in the foreground
  • previewDrag - Defaults to false - Does not work if toBack is set to false
  • storeToFile - Defaults to false - Capture images to a file and return back the file path instead of returning base64 encoded data.
  • disableExifHeaderStripping - Defaults to false - Android Only - Disable automatic rotation of the image, and let the browser deal with it (keep reading on how to achieve it)
let options = {
  x: 0,
  y: 0,
  width: window.screen.width,
  height: window.screen.height,
  camera: CameraPreview.CAMERA_DIRECTION.BACK,
  toBack: false,
  tapPhoto: true,
  tapFocus: false,
  previewDrag: false,
  storeToFile: false,
  disableExifHeaderStripping: false
};

CameraPreview.startCamera(options);

When setting toBack to true, remember to add the style below on your app's HTML or body element:

html, body, .ion-app, .ion-content {
  background-color: transparent;
}

When both tapFocus and tapPhoto are true, the camera will focus, and take a picture as soon as the camera is done focusing.

If you capture large images in Android you may notice that performace is poor, in those cases you can set disableExifHeaderStripping to true and instead just add some extra Javascript/HTML to get a proper display of your captured images without risking your application speed.

When capturing large images you may want them to be stored into a file instead of having them base64 encoded, as enconding at least on Android is very expensive. With the feature storeToFile enabled the plugin will capture the image into a temporary file inside the application temporary cache (the same place where Cordova will extract your assets). This method is better used with disableExifHeaderStripping to get the best possible performance.

stopCamera([successCallback, errorCallback])

Stops the camera preview instance.

CameraPreview.stopCamera();

switchCamera([successCallback, errorCallback])

Switch between the rear camera and front camera, if available.

CameraPreview.switchCamera();

show([successCallback, errorCallback])

Show the camera preview box.

CameraPreview.show();

hide([successCallback, errorCallback])

Hide the camera preview box.

CameraPreview.hide();

takePicture(options, successCallback, [errorCallback])

Take the picture. If width and height are not specified or are 0 it will use the defaults. If width and height are specified, it will choose a supported photo size that is closest to width and height specified and has closest aspect ratio to the preview. The argument quality defaults to 85 and specifies the quality/compression value: 0=max compression, 100=max quality.

CameraPreview.takePicture({width:640, height:640, quality: 85}, function(base64PictureData|filePath) {
  /*
    if the storeToFile option is false (the default), then base64PictureData is returned.
    base64PictureData is base64 encoded jpeg image. Use this data to store to a file or upload.
    Its up to the you to figure out the best way to save it to disk or whatever for your application.
  */

  /*
    if the storeToFile option is set to true, then a filePath is returned. Note that the file
    is stored in temporary storage, so you should move it to a permanent location if you
    don't want the OS to remove it arbitrarily.
  */

  // One simple example is if you are going to use it inside an HTML img src attribute then you would do the following:
  imageSrcData = 'data:image/jpeg;base64,' + base64PictureData;
  $('img#my-img').attr('src', imageSrcData);
});

// OR if you want to use the default options.

CameraPreview.takePicture(function(base64PictureData){
  /* code here */
});

takeSnapshot(options, successCallback, [errorCallback])

Take snapshot of the camera preview. The resulting image will be the same size as specified in startCamera options. The argument quality defaults to 85 and specifies the quality/compression value: 0=max compression, 100=max quality.

CameraPreview.takeSnapshot({quality: 85}, function(base64PictureData){
  /*
    base64PictureData is base64 encoded jpeg image. Use this data to store to a file or upload.
  */

  // One simple example is if you are going to use it inside an HTML img src attribute then you would do the following:
  imageSrcData = 'data:image/jpeg;base64,' +base64PictureData;
  $('img#my-img').attr('src', imageSrcData);
});

getSupportedFocusModes(cb, [errorCallback])

Get focus modes supported by the camera device currently started. Returns an array containing supported focus modes. See FOCUS_MODE for possible values that can be returned.

CameraPreview.getSupportedFocusModes(function(focusModes){
  focusModes.forEach(function(focusMode) {
    console.log(focusMode + ', ');
  });
});

setFocusMode(focusMode, [successCallback, errorCallback])

Set the focus mode for the camera device currently started.

CameraPreview.setFocusMode(CameraPreview.FOCUS_MODE.CONTINUOUS_PICTURE);

getFocusMode(cb, [errorCallback])

Get the focus mode for the camera device currently started. Returns a string representing the current focus mode.See FOCUS_MODE for possible values that can be returned.

CameraPreview.getFocusMode(function(currentFocusMode){
  console.log(currentFocusMode);
});

getSupportedFlashModes(cb, [errorCallback])

Get the flash modes supported by the camera device currently started. Returns an array containing supported flash modes. See FLASH_MODE for possible values that can be returned

CameraPreview.getSupportedFlashModes(function(flashModes){
  flashModes.forEach(function(flashMode) {
    console.log(flashMode + ', ');
  });
});

setFlashMode(flashMode, [successCallback, errorCallback])

Set the flash mode. See FLASH_MODE for details about the possible values for flashMode.

CameraPreview.setFlashMode(CameraPreview.FLASH_MODE.ON);

getFlashMode(cb, [errorCallback])

Get the flash mode for the camera device currently started. Returns a string representing the current flash mode.See FLASH_MODE for possible values that can be returned

CameraPreview.getFlashMode(function(currentFlashMode){
  console.log(currentFlashMode);
});

getHorizontalFOV(cb, [errorCallback])

Get the Horizontal FOV for the camera device currently started. Returns a string of a float that is the FOV of the camera in Degrees.

CameraPreview.getHorizontalFOV(function(getHorizontalFOV){
  console.log(getHorizontalFOV);
});

getSupportedColorEffects(cb, [errorCallback])

Currently this feature is for Android only. A PR for iOS support would be happily accepted

Get color modes supported by the camera device currently started. Returns an array containing supported color effects (strings). See COLOR_EFFECT for possible values that can be returned.

CameraPreview.getSupportedColorEffects(function(colorEffects){
  colorEffects.forEach(function(color) {
    console.log(color + ', ');
  });
});

setColorEffect(colorEffect, [successCallback, errorCallback])

Set the color effect. See COLOR_EFFECT for details about the possible values for colorEffect.

CameraPreview.setColorEffect(CameraPreview.COLOR_EFFECT.NEGATIVE);

setZoom(zoomMultiplier, [successCallback, errorCallback])

Set the zoom level for the camera device currently started. zoomMultipler option accepts an integer. Zoom level is initially at 1

CameraPreview.setZoom(2);

getZoom(cb, [errorCallback])

Get the current zoom level for the camera device currently started. Returns an integer representing the current zoom level.

CameraPreview.getZoom(function(currentZoom){
  console.log(currentZoom);
});

getMaxZoom(cb, [errorCallback])

Get the maximum zoom level for the camera device currently started. Returns an integer representing the manimum zoom level.

CameraPreview.getMaxZoom(function(maxZoom){
  console.log(maxZoom);
});

getSupportedWhiteBalanceModes(cb, [errorCallback])

Returns an array with supported white balance modes for the camera device currently started. See WHITE_BALANCE_MODE for details about the possible values returned.

CameraPreview.getSupportedWhiteBalanceModes(function(whiteBalanceModes){
  console.log(whiteBalanceModes);
});

getWhiteBalanceMode(cb, [errorCallback])

Get the curent white balance mode of the camera device currently started. See WHITE_BALANCE_MODE for details about the possible values returned.

CameraPreview.getWhiteBalanceMode(function(whiteBalanceMode){
  console.log(whiteBalanceMode);
});

setWhiteBalanceMode(whiteBalanceMode, [successCallback, errorCallback])

Set the white balance mode for the camera device currently started. See WHITE_BALANCE_MODE for details about the possible values for whiteBalanceMode.

CameraPreview.setWhiteBalanceMode(CameraPreview.WHITE_BALANCE_MODE.CLOUDY_DAYLIGHT);

getExposureModes(cb, [errorCallback])

Returns an array with supported exposure modes for the camera device currently started. See EXPOSURE_MODE for details about the possible values returned.

CameraPreview.getExposureModes(function(exposureModes){
  console.log(exposureModes);
});

getExposureMode(cb, [errorCallback])

Get the curent exposure mode of the camera device currently started. See EXPOSURE_MODE for details about the possible values returned.

CameraPreview.getExposureMode(function(exposureMode){
  console.log(exposureMode);
});

setExposureMode(exposureMode, [successCallback, errorCallback])

Set the exposure mode for the camera device currently started. See EXPOSURE_MODE for details about the possible values for exposureMode.

CameraPreview.setExposureMode(CameraPreview.EXPOSURE_MODE.CONTINUOUS);

getExposureCompensationRange(cb, [errorCallback])

Get the minimum and maximum exposure compensation for the camera device currently started. Returns an object containing min and max integers.

CameraPreview.getExposureCompensationRange(function(expoxureRange){
  console.log("min: " + exposureRange.min);
  console.log("max: " + exposureRange.max);
});

getExposureCompensation(cb, [errorCallback])


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap