中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
相机拍照界面应该怎样拉起?
微信扫码分享
import { common } from '@kit.AbilityKit'; import { camera, cameraPicker } from '@kit.CameraKit'; import { BusinessError } from '@kit.BasicServicesKit'; let context = getContext(this) as common.Context; async function startCameraPicker() { try { let pickerProfile: cameraPicker.PickerProfile = { cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK }; let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(context, [cameraPicker.PickerMediaType.PHOTO, cameraPicker.PickerMediaType.VIDEO], pickerProfile); console.log("the pick pickerResult is:" + JSON.stringify(pickerResult)); } catch (error) { let err = error as BusinessError; console.error(`the pick call failed. error code: ${err.code}`); } } @Entry @Component struct StartCameraPickerView { build() { Column() { Button("点击拉起相机") .onClick(() => startCameraPicker()) } .width("100%") .height("100%") .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) } }