中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
直接使用相机拍照能力
微信扫码分享
import common from ‘@ohos.app.ability.common’; import Want from ‘@ohos.app.ability.Want’; function startImageCapture(context: common.UIAbilityContext): void { let want: Want = { action: ‘ohos.want.action.imageCapture’, parameters: { callBundleName: ‘com.example.myapplication15’, supportMultiMode: false } }; context.startAbilityForResult(want, (err, data) => { if (err.code) { console.error(Failed to start ability for result. Code is ${err.code}, message is ${err.message}); return; } console.info(Succeeded in starting ability for result. Data is ${JSON.stringify(data)}); }) } @Entry @Component struct Page { @State message: string = ‘Hello World’; build() { Row() { Column() { Text(this.message) .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(() => { const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; startImageCapture(context); }) } .width(‘100%’) } .height(‘100%’) } }