(照相機)Camera

Camera

拍照或拍攝視頻。需要和Cordova插件:cordova-plugin-camera
。 有關(guān)更多信息,請參閱Cordova Camera Plugin Docs.
Repo(備用): https://github.com/apache/cordova-plugin-camera

Installation(安裝)

1.安裝Cordova和Ionic原生插件:

$ ionic cordova plugin add cordova-plugin-camera
$ npm install --save @ionic-native/camera

2.添加插件到app's module

Supported platforms(支持平臺)

Android
BlackBerry 10
Browser
Firefox OS
iOS
Ubuntu
Windows
Windows Phone 8

Usage(用法)

import { Camera, CameraOptions } from '@ionic-native/camera';

constructor(private camera: Camera) { }

...


const options: CameraOptions = {
  quality: 100,
  destinationType: this.camera.DestinationType.DATA_URL,
  encodingType: this.camera.EncodingType.JPEG,
  mediaType: this.camera.MediaType.PICTURE
}

this.camera.getPicture(options).then((imageData) => {
 // imageData is either a base64 encoded string or a file URI
 // If it's base64:
 let base64Image = 'data:image/jpeg;base64,' + imageData;
}, (err) => {
 // Handle error
});

Instance Members(實例成員)

DestinationType

可能的destination類型常量

EncodingType

Convenience constant

MediaType

Convenience constant

PictureSourceType

Convenience constant

PopoverArrowDirection

Convenience constant

Direction

Convenience constant

getPicture(options)

拍攝照片或視頻,或從文件庫加載。

參數(shù) 類型 詳情
options CameraOptions 您要傳送到相機的選項。 編碼類型,質(zhì)量等。平臺特有的選項在 Cordova plugin docs.可選

****Returns:** Promise<any>
返回使用Base64編碼圖像數(shù)據(jù)或圖像文件URI的promise,具體取決于cameraOptions,否則將以錯誤方式rejects。

cleanup()

Platforms:****IOS
調(diào)用camera.getPicture后,刪除保存在臨時存儲器中的中間圖像文件。 僅適用于Camera.sourceType的值等于Camera.PictureSourceType.CAMERA和Camera.destinationType等于Camera.DestinationType.FILE_URI。
****Returns:** Promise<any>

CameraOptions

參數(shù) 類型 詳情
quality number 圖像質(zhì)量范圍0-100。 默認(rèn)值為50 (可選)
destinationType number 選擇返回值的格式。 在Camera.DestinationType中定義。 默認(rèn)為FILE_URI。 DATA_URL:0,返回圖像為base64編碼的字符串,F(xiàn)ILE_URI:1,返回圖像文件URI,NATIVE_URI:2返回圖片本機URI(例如,iOS上的資產(chǎn)庫://或Android上的內(nèi)容//)(可選)
sourceType number 設(shè)置圖片的來源。 定義在Camera.PictureSourceType。 默認(rèn)為CAMERA。 PHOTOLIBRARY:0,CAMERA:1,SAVEDPHOTOALBUM:2 (可選)
allowEdit boolean 允許在選擇前簡單地編輯圖像(可選)
encodingType number 選擇返回的圖像文件的編碼。 在Camera.EncodingType中定義。 默認(rèn)為JPEG JPEG:0返回JPEG編碼圖像PNG:1返回PNG編碼圖像(可選)
targetWidth number 寬度以像素為單位縮放圖像。 必須與targetHeight一起使用。 長寬比保持不變(可選)
targetHeight number 高度以像素為單位縮放圖像。 必須與targetWidth一起使用。 長寬比保持不變(可選)
mediaType number 設(shè)置要選擇的媒體類型。 僅當(dāng)PictureSourceType為PHOTOLIBRARY或SAVEDPHOTOALBUM時才有效。 在Camera.MediaType中定義圖片:0允許僅選擇靜態(tài)圖片。 默認(rèn)。 將通過DestinationType VIDEO指定的格式:1允許僅選擇視頻,將始終返回FILE_URI ALLMEDIA:2允許從所有媒體類型中進(jìn)行選擇(可選)
correctOrientation boolean 旋轉(zhuǎn)圖像以在捕獲期間校正設(shè)備的方向。(可選)
saveToPhotoAlbum boolean 拍攝后將圖像保存到設(shè)備上的相冊(可選)
cameraDirection number 選擇要使用的相機(正面或背面)。 在Camera.Direction中定義。 默認(rèn)為BACK。 BACK:0 FRONT:1 (可選)
popoverOptions CameraPopoverOptions 僅iOS選項,在iPad上指定Popover的位置。 在相機中定義Popover選項(可選)

CameraPopoverOptions

參數(shù) 類型 詳情
x number
y number
width number
height number
arrowDir number 方向箭頭應(yīng)該在popover的位置。 在Camera.PopoverArrowDirection中定義匹配iOS UIPopoverArrowDirection常量。 ARROW_UP:1,ARROW_DOWN:2,ARROW_LEFT:4,ARROW_RIGHT:8,ARROW_ANY:15
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容