成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

OpenHarmony3.2 beta4上照相機的使用之1--開啟照相機預(yù)覽畫面

系統(tǒng) OpenHarmony
這里為何我特意強調(diào)是OpenHarmony3.2 beta4,因為我發(fā)現(xiàn)即使同為3.2版本,beta4上的Camera相關(guān)的api和beta2版本差距都非常大,于是選取了當(dāng)前最新的版本進行講解。

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??

隨著OpenHarmony的版本更新,在3.2上已經(jīng)提供了非常豐富的API來調(diào)用照相機。此處講解的是原生的使用相機的流程,并發(fā)像Android普通應(yīng)用開發(fā)一樣通過一個intent直接調(diào)用系統(tǒng)相機應(yīng)用進行拍照,根據(jù)原生的調(diào)用相機的API可以讓大家自己定義功能更加豐富的相機應(yīng)用。

這里為何我特意強調(diào)是OpenHarmony3.2 beta4,因為我發(fā)現(xiàn)即使同為3.2版本,beta4上的Camera相關(guān)的api和beta2版本差距都非常大,于是選取了當(dāng)前最新的版本進行講解。

既然使用相機,那么第一步是先想辦法把相機點亮,即能通過攝像頭看到預(yù)覽畫面,后面才是拍照、錄像、分布式拍照等功能實現(xiàn)。

關(guān)于sdk的問題

目前在OpenHarmony3.2上調(diào)用相機,需要使用ohos-full-sdk,而非大家下載DevEco Studio所帶的sdk,那個sdk被稱作為public sdk。關(guān)于sdk的替換辦法可以參考官方文檔“ ??full-SDK替換指南??”,我這里不過多贅述。

此處核心要注意的一點是,目前我3.2 beta4上用的sdk對應(yīng)的版本號為3.2.9.4

OpenHarmony3.2 beta4上照相機的使用之1--開啟照相機預(yù)覽畫面-開源基礎(chǔ)軟件社區(qū)

而目前官方文檔上寫的能下載到的sdk最高版本只有3.2.5.6。

OpenHarmony3.2 beta4上照相機的使用之1--開啟照相機預(yù)覽畫面-開源基礎(chǔ)軟件社區(qū)

因此,需要我們手動下載系統(tǒng)源碼,自己完成sdk的編譯才行,我這里是基于3.2 beta4的系統(tǒng)源碼自行編譯出來的full-sdk。

啟用相機打開預(yù)覽畫面核心流程與代碼實現(xiàn)

(1)動態(tài)權(quán)限申請

需要獲取ohos.permission.CAMERA權(quán)限

(2)相機相關(guān)API操作流程

OpenHarmony3.2 beta4上照相機的使用之1--開啟照相機預(yù)覽畫面-開源基礎(chǔ)軟件社區(qū)

上面是相機完整功能使用的時序圖,這里我們先只按照時序圖中的流程只實現(xiàn)預(yù)覽部分。

(3)配合XComponent組件完成相機預(yù)覽流的輸出

XComponent組件中通過XComponentController的getXComponentSurfaceId方法可以獲取到sufaceId,然后通過相機管理對象cameraManager.createPreviewOutput這個關(guān)鍵方法可以綁定該surface,從而實現(xiàn)預(yù)覽畫面的輸出。

啟用相機打開預(yù)覽畫面代碼實現(xiàn)

import camera from '@ohos.multimedia.camera'

const PERMISSIONS: Array<string> = [
'ohos.permission.CAMERA']
let previewWidth;
let previewHeight;
@Entry
@Component
struct Index {
private mXComponentController: XComponentController = new XComponentController()
private surfaceId: string = '-1'

async initCamera(surfaceId: string){
//動態(tài)獲取隱私權(quán)限
let context = getContext(this) as any
await context.requestPermissionsFromUser(PERMISSIONS)
console.log('grantPermission,requestPermissionsFromUser');
// 創(chuàng)建CameraManager對象
let cameraManager = await camera.getCameraManager(context)
if (!cameraManager) {
console.error('Failed to get the CameraManager instance');
}
// 獲取相機列表
let cameraArray = await cameraManager.getSupportedCameras()
if (!cameraArray) {
console.error('Failed to get the cameras');
}
for (let index = 0; index < cameraArray.length; index++) {
console.log('cameraId : ' + cameraArray[index].cameraId) // 獲取相機ID
console.log('cameraPosition : ' + cameraArray[index].cameraPosition) // 獲取相機位置
console.log('cameraType : ' + cameraArray[index].cameraType) // 獲取相機類型
console.log('connectionType : ' + cameraArray[index].connectionType) // 獲取相機連接類型
}

// 創(chuàng)建相機輸入流
let cameraInput = await cameraManager.createCameraInput(cameraArray[0])

// 打開相機
await cameraInput.open().then(() => {
console.log('opencamera succ.');
}).catch(function(err){
console.log("opencamera failed with error:"+ err);
});

// 獲取相機設(shè)備支持的輸出流能力
let cameraOutputCap = await cameraManager.getSupportedOutputCapability(cameraArray[0]);
if (!cameraOutputCap) {
console.error("outputCapability outputCapability == null || undefined")
} else {
console.log("outputCapability: " + JSON.stringify(cameraOutputCap));
}

//獲取相機支持的輸出能力--支持的預(yù)覽配置信息
let previewProfilesArray = cameraOutputCap.previewProfiles;
if (!previewProfilesArray) {
console.error("createOutput previewProfilesArray == null || undefined")
}else{
console.log("previewProfiles:"+JSON.stringify(previewProfilesArray[0]))
previewWidth = previewProfilesArray[0].size.width;
previewHeight = previewProfilesArray[0].size.height;
}

// 創(chuàng)建預(yù)覽輸出流,其中參數(shù) surfaceId 參考下面 XComponent 組件,預(yù)覽流為XComponent組件提供的surface
let previewOutput = await cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId)
if (!previewOutput) {
console.error("Failed to create the PreviewOutput instance.")
}else{
console.log("create the PreviewOutput instance succ.")
}

//創(chuàng)建會話
let captureSession = await cameraManager.createCaptureSession()
if (!captureSession) {
console.error('Failed to create the CaptureSession instance.');
return;
}
console.log('Callback returned with the CaptureSession instance.' + captureSession);

// 開始配置會話
await captureSession.beginConfig().then(()=>{
console.log('captureSession beginConfig succ');
}).catch(function(err){
console.log("captureSession beginConfig failed with error:"+ err);
});

// 向會話中添加相機輸入流
await captureSession.addInput(cameraInput).then(() => {
console.log('captureSession addInput instance is added.');
}).catch(function(err){
console.log("captureSession addInput failed with error:"+ err);
});

// 向會話中添加預(yù)覽輸入流
await captureSession.addOutput(previewOutput).then(() => {
console.log('captureSession addOutput previewOutput instance is added.');
}).catch(function(err){
console.log("captureSession addOutput previewOutput failed with error:"+ err);
});

// 提交會話配置
await captureSession.commitConfig().then(() => {
console.log('captureSession commitConfig success.');
}).catch(function(err){
console.log("captureSession commitConfig failed with error:"+ err);
});
// 啟動會話
await captureSession.start().then(() => {
console.log('captureSession start success.');
}).catch(function(err){
console.log("captureSession start failed with error:"+ err);
});
}

build() {
Flex() {
XComponent({ // 創(chuàng)建XComponent
id: '',
type: 'surface',
libraryname: '',
controller: this.mXComponentController
})
.onLoad(() => { // 設(shè)置onload回調(diào)
// 設(shè)置Surface寬高(1920*1080),預(yù)覽尺寸設(shè)置參考前面 previewProfilesArray 獲取的當(dāng)前設(shè)備所支持的預(yù)覽分辨率大小去設(shè)置
this.mXComponentController.setXComponentSurfaceSize({surfaceWidth:previewWidth,surfaceHeight:previewHeight})
// 獲取Surface ID
this.surfaceId = this.mXComponentController.getXComponentSurfaceId()
this.initCamera(this.surfaceId)
})
.width('100%') // 設(shè)置XComponent寬度
.height('100%') // 設(shè)置XComponent高度
}
}

}

??想了解更多關(guān)于開源的內(nèi)容,請訪問:??

??51CTO 開源基礎(chǔ)軟件社區(qū)??

??https://ost.51cto.com??

責(zé)任編輯:jianghua 來源: 51CTO 開源基礎(chǔ)軟件社區(qū)
相關(guān)推薦

2011-07-29 10:41:27

IPhone 應(yīng)用開發(fā) 照相機

2015-11-17 11:02:35

2021-11-02 22:50:10

鼠標(biāo)計算機傳感器

2017-05-23 10:17:40

互聯(lián)網(wǎng)

2022-12-02 18:26:33

開源鴻蒙OpenHarmon

2013-04-19 15:23:11

高新技術(shù)

2022-05-27 15:04:53

鴻蒙操作系統(tǒng)

2012-03-02 10:35:22

金山快盤云相機

2022-08-24 14:50:09

谷歌3D

2013-11-18 10:27:05

Tizen智能家居

2011-06-10 16:33:54

iOS 5蘋果

2023-02-13 15:54:49

2011-05-03 16:50:08

激光打印機工作原理

2013-04-19 14:31:12

影像

2012-05-23 14:57:21

噴墨打印機評測

2017-01-09 13:01:04

辦公系統(tǒng)
點贊
收藏

51CTO技術(shù)棧公眾號

主站蜘蛛池模板: 成年人黄色一级片 | 亚洲成网站 | 亚洲日韩中文字幕一区 | 国产永久免费 | 欧美视频在线播放 | 国产一级片91| 视频精品一区二区三区 | 精品国产一区二区三区日日嗨 | 免费国产一区二区 | av在线天天 | 高清视频一区二区三区 | av在线视| 午夜综合 | 国产精品免费福利 | 日本成人片在线观看 | 国产精品日韩欧美 | 精品一区二区三区在线播放 | 性色在线| 欧美福利网站 | 97色在线视频 | 欧美xxxx性xxxxx高清 | 免费观看一级特黄欧美大片 | 国产视频一区二区 | 日韩一二区 | 荷兰欧美一级毛片 | 男女爱爱网站 | 久久久亚洲一区 | 国产色在线 | 欧美网站一区 | 欧美在线网站 | 狠狠色综合久久婷婷 | 国产一区2区 | 免费在线看黄视频 | 久久精品久久精品久久精品 | 国产中的精品av涩差av | 香蕉一区| 色免费看 | 日本久久久影视 | 成人a视频 | 成人免费小视频 | 国产成人综合亚洲欧美94在线 |