当前位置: 首页> 教育> 幼教 > 一级造价工程师报名_中策大数据工程信息网_超级软文_百度关键词关键词大全

一级造价工程师报名_中策大数据工程信息网_超级软文_百度关键词关键词大全

时间:2025/7/12 7:39:16来源:https://blog.csdn.net/m0_64778763/article/details/147193538 浏览次数:2次
一级造价工程师报名_中策大数据工程信息网_超级软文_百度关键词关键词大全

相机应用可通过创建相机输入流调用并控制相机设备,创建不同类型的输出流,进而实现预览、拍照、录像等基础功能。

开发步骤

在创建相机设备输入之前需要先完成相机设备管理,详细开发步骤可参考上一篇文章。

创建相机输入流

通过cameraManager类的createCameraInput方法创建相机输入流,监听相机输入流错误事件并打开相机

import { camera } from '@kit.CameraKit';
import { BusinessError } from '@kit.BasicServicesKit';async function createInput(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): Promise<camera.CameraInput | undefined> {// 创建相机输入流。let cameraInput: camera.CameraInput | undefined = undefined;try {cameraInput = cameraManager.createCameraInput(cameraDevice);} catch (error) {let err = error as BusinessError;console.error(`The createCameraInput call failed. error code: ${err.code}`);}if (cameraInput === undefined) {return undefined;}// 监听cameraInput错误信息。cameraInput.on('error', cameraDevice, (error: BusinessError) => {console.error(`Camera input error code: ${error.code}`);});// 打开相机。await cameraInput.open();return cameraInput;
}

获取相机支持的模式列表

调用getSupportedSceneModes方法,获取当前相机设备支持的所有模式列表SceneMode数组

function getSupportedSceneMode(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager): Array<camera.SceneMode> {// 获取相机设备支持的模式列表let sceneModeArray: Array<camera.SceneMode> = cameraManager.getSupportedSceneModes(cameraDevice);if (sceneModeArray != undefined && sceneModeArray.length > 0) {for (let index = 0; index < sceneModeArray.length; index++) {console.info('Camera SceneMode : ' + sceneModeArray[index]);  }return sceneModeArray;} else {console.error("cameraManager.getSupportedSceneModes error");return [];}
}

相机支持的模式包括NORMAL_PHOTO(普通拍照模式)、NORMAL_VIDEO(普通录像模式)和SECURE_PHOTO(安全相机模式)。

获取相机支持的输出流

获取当前相机设备支持的所有输出流:通过getSupportedOutputCapability方法,获取当前相机设备支持的所有输出流,如预览流、拍照流、录像流等。输入CameraDevice和SceneMode,获取CameraOutputCapability相机输出能力,不同输出流的能力保存在CameraOutputCapability中的各个profile字段中

async function getSupportedOutputCapability(cameraDevice: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): Promise<camera.CameraOutputCapability | undefined> {// 获取相机设备支持的输出流能力。let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(cameraDevice, sceneMode);if (!cameraOutputCapability) {console.error("cameraManager.getSupportedOutputCapability error");return undefined;}console.info("outputCapability: " + JSON.stringify(cameraOutputCapability));// previewProfiles属性为获取当前设备支持的预览输出流。let previewProfilesArray: Array<camera.Profile> = cameraOutputCapability.previewProfiles;if (!previewProfilesArray) {console.error("getSupportedOutputCapability previewProfilesArray == null || undefined");}//photoProfiles属性为获取当前设备支持的拍照输出流。let photoProfilesArray: Array<camera.Profile> = cameraOutputCapability.photoProfiles;if (!photoProfilesArray) {console.error("getSupportedOutputCapability photoProfilesArray == null || undefined");}//videoProfiles属性为获取当前设备支持的录像输出流。let videoProfilesArray: Array<camera.VideoProfile> = cameraOutputCapability.videoProfiles;if (!videoProfilesArray) {console.error("getSupportedOutputCapability videoProfilesArray == null || undefined");}//supportedMetadataObjectTypes属性为获取当前设备支持的metadata流类型信息集合,目前只定义了FACE_DETECTION用于人脸检测的metadata类型let metadataObjectTypesArray: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes;if (!metadataObjectTypesArray) {console.error("getSupportedOutputCapability metadataObjectTypesArray== null || undefined");}return cameraOutputCapability;
} 

创建相机输出流

根据用户需求创建不同类型的输出流

//创建预览流
function createPreviewOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability, surfaceId: string): camera.PreviewOutput | undefined {let previewProfilesArray: Array<camera.Profile> = cameraOutputCapability.previewProfiles;let previewOutput: camera.PreviewOutput | undefined = undefined;try {previewOutput = cameraManager.createPreviewOutput(previewProfilesArray[0], surfaceId);} catch (error) {let err = error as BusinessError;console.error(`The createPreviewOutput call failed. error code: ${err.code}`);}return previewOutput;
}// 创建拍照流
function createPhotoOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): camera.PhotoOutput | undefined {let photoProfilesArray: Array<camera.Profile> = cameraOutputCapability.photoProfiles;let photoOutput: camera.PhotoOutput | undefined = undefined;try {photoOutput = cameraManager.createPhotoOutput(photoProfilesArray[0]);} catch (error) {let err = error as BusinessError;console.error(`The createPhotoOutput call failed. error code: ${err.code}`);}return photoOutput;
}//创建录像流
function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {let videoProfilesArray: Array<camera.VideoProfile> = cameraOutputCapability.videoProfiles;let videoOutput: camera.VideoOutput | undefined = undefined;try {videoOutput = cameraManager.createVideoOutput(videoProfilesArray[0], surfaceId);} catch (error) {let err = error as BusinessError;console.error(`The createVideoOutput call failed. error code: ${err.code}`);}return videoOutput;
}

API参考

createCameraInput

createCameraInput(camera: CameraDevice): CameraInput

使用CameraDevice对象创建CameraInput实例,同步返回结果。
参数CameraDevice对象,通过 CameraManager.getSupportedCameras 接口获取。

createCameraInput(position: CameraPosition, type: CameraType): CameraInput

根据相机位置和类型创建CameraInput实例,同步返回结果。

getSupportedSceneModes

getSupportedSceneModes(camera: CameraDevice): Array<SceneMode>enum SceneMode {NORMAL_PHOTO = 1,   // 普通拍照模式NORMAL_VIDEO = 2,   // 普通录像模式SECURE_PHOTO = 12,  // 安全相机模式...                 // 其余模式为system api,如人像、夜景、专业拍照模式等
}

getSupportedOutputCapability

getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapabilityinterface CameraOutputCapability {readonly previewProfiles: Array<Profile>;readonly photoProfiles: Array<Profile>;readonly videoProfiles: Array<VideoProfile>;readonly depthProfiles: Array<DepthProfile>; //深度数据配置信息,systemapireadonly supportedMetadataObjectTypes: Array<MetadataObjectType>;}

查询相机设备在某种模式下支持的输出能力,同步返回结果

关键字:一级造价工程师报名_中策大数据工程信息网_超级软文_百度关键词关键词大全

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: