OpenHarmony开发者论坛
标题:
openharmony 6.0 开发中 Camera 拍照 成功之后 如何才能触发 photoAvailable
[打印本页]
作者:
AMove
时间:
2026-2-2 14:32
标题:
openharmony 6.0 开发中 Camera 拍照 成功之后 如何才能触发 photoAvailable
[md]### 【问题描述】
1. 设备连接了一个高拍仪 用系统拍照可以正常的拍照,但是 使用自己写的代码之后 可以预览 但是拍照 看日志成功之后 但是无法触发 photoAvailable 这个方法 所以拿不到
2. 相关的代码(请勿使用截图)
```
// CameraManager.ts
import { BusinessError, emitter } from '@kit.BasicServicesKit';
import { camera } from '@kit.CameraKit';
import { LogUtil } from '../uitls/LogUtil';
import { display } from '@kit.ArkUI';
import { image } from '@kit.ImageKit';
import { ImageUtil } from '../uitls/ImageUtil';
import {
EVENT_CAPTURE_FAIL,
EVENT_CAPTURE_SUCCESS,
EVENT_INIT_CAMERA_FAIL,
EVENT_INIT_CAMERA_SUCCESS
} from '../datas/Consts';
import libOpencv from 'libopencv.so';
const TAG = 'CameraManager';
export class CameraManager {
private cameraManager: camera.CameraManager | undefined = undefined;
private cameraInput: camera.CameraInput | undefined = undefined;
private previewOutput: camera.PreviewOutput | undefined = undefined;
private photoOutput: camera.PhotoOutput | undefined = undefined; // ✅ 正确类型
private session: camera.PhotoSession | undefined = undefined;
private context: Context | undefined = undefined;
private isCapture: number = 0;
// PixelMap 格式映射(按需保留)
private formatToPixelMapFormatMap = new Map<number, image.PixelMapFormat>([
[12, image.PixelMapFormat.RGBA_8888],
[25, image.PixelMapFormat.NV21],
[35, image.PixelMapFormat.YCBCR_P010],
[36, image.PixelMapFormat.YCRCB_P010]
]);
// PixelMapFormat格式的单个像素点大小映射关系。
private pixelMapFormatToSizeMap = new Map<image.PixelMapFormat, number>([
[image.PixelMapFormat.RGBA_8888, 4],
[image.PixelMapFormat.NV21, 1.5],
[image.PixelMapFormat.YCBCR_P010, 3],
[image.PixelMapFormat.YCRCB_P010, 3]
]);
/**
* 获取可用相机(直接返回第一个,适配高拍仪复用 lcam001 的场景)
*/
getUsbCamera(context: Context): camera.CameraDevice | undefined {
LogUtil.debug(TAG, `调用 getUsbCamera`);
this.context = context;
try {
this.cameraManager = camera.getCameraManager(context);
const cameraArray = this.cameraManager.getSupportedCameras();
if (cameraArray.length === 0) {
LogUtil.debug(TAG, '没有可用的相机设备');
return undefined;
}
// 直接返回第一个相机(即 lcam001),不判断 connectionType
const usbCamera = cameraArray[0];
LogUtil.debug(TAG, `使用相机: ID= ${usbCamera.cameraId}, 连接类型= ${usbCamera.connectionType}`);
return usbCamera;
} catch (error) {
LogUtil.error(TAG, `getUsbCamera error: ${JSON.stringify(error)}`);
return undefined;
}
}
/**
* 初始化相机
*/
async initCamera(context: Context, surfaceId: string): Promise<void> {
LogUtil.debug(TAG, `调用 initCamera`);
const usbCamera = this.getUsbCamera(context);
if (!usbCamera || !this.cameraManager) {
LogUtil.error(TAG, '获取相机设备失败');
emitter.emit(EVENT_INIT_CAMERA_FAIL);
return;
}
try {
// 创建相机输入
this.cameraInput = this.cameraManager.createCameraInput(usbCamera);
this.cameraInput.on('error', usbCamera, (err: BusinessError) => {
LogUtil.error(TAG, `Camera input error code: ${err.code}`);
});
await this.cameraInput.open();
// 获取能力
const capability = this.cameraManager.getSupportedOutputCapability(
usbCamera,
camera.SceneMode.NORMAL_PHOTO
);
LogUtil.debug(TAG, `previewProfiles: ${JSON.stringify(capability.previewProfiles)}`);
LogUtil.debug(TAG, `photoProfiles: ${JSON.stringify(capability.photoProfiles)}`);
// 选择配置(这里简单选最大分辨率,可按需调整)
const previewProfile = this.getPreviewProfile(capability.previewProfiles);
const photoProfile = this.getPhotoProfile(capability.photoProfiles);
// 创建预览输出(绑定到 UI)
this.previewOutput = this.cameraManager.createPreviewOutput(previewProfile, surfaceId);
this.setPreviewOutputCb();
// ✅ 创建拍照输出(关键修复!)
this.photoOutput = this.cameraManager.createPhotoOutput(photoProfile);
this.setPhotoOutputCb();
// 创建会话
this.session = this.cameraManager.createSession(camera.SceneMode.NORMAL_PHOTO) as camera.PhotoSession;
this.session.beginConfig();
this.session.addInput(this.cameraInput);
this.session.addOutput(this.previewOutput);
LogUtil.debug(TAG, `添加输出流(预览流)成功`)
this.session.addOutput(this.photoOutput); // ✅ 正确添加 PhotoOutput
LogUtil.debug(TAG, `添加输出流(拍照流)成功`)
await this.session.commitConfig();
// 启动会话
const rotation = display.getDefaultDisplaySync().rotation;
LogUtil.debug(TAG, `Display rotation: ${rotation}`);
await this.session.start();
LogUtil.debug(TAG, `this.session: ${this.session}`);
this.configuringSession();
emitter.emit(EVENT_INIT_CAMERA_SUCCESS);
LogUtil.debug(TAG, '相机初始化成功');
} catch (error) {
const err = error as BusinessError;
LogUtil.error(TAG, `初始化相机失败: ${JSON.stringify(err)}`);
emitter.emit(EVENT_INIT_CAMERA_FAIL);
await this.releaseCamera(); // 确保失败时释放资源
}
}
/**
* 设置预览回调(新增帧捕获)
*/
setPreviewOutputCb(): void {
this.previewOutput?.on('frameStart', () => {
LogUtil.debug(TAG, '预览帧开始');
});
// this.previewOutput?.on('frameArrival', async () => {
// try {
// const imageReceiver = this.previewOutput?.getImageReceiver();
// if (!imageReceiver) return;
//
// const image = await imageReceiver.readNextImage();
// if (!image) return;
//
// // 获取图像数据
// const buffer = await image.getComponent(image.ComponentType.YUV);
// const pixelMap = await image.createPixelMap();
//
// // 保存图片(使用已有工具类)
// const path = await ImageUtil.savePixelMap(
// pixelMap,
// `${this.context?.filesDir}/preview_frames`,
// `frame_${Date.now()}.jpg`,
// 'image/jpeg'
// );
//
// LogUtil.debug(TAG, `预览帧已保存至:${path}`);
// image.close();
// } catch (err) {
// LogUtil.error(TAG, `获取预览帧失败:${JSON.stringify(err)}`);
// }
// });
this.previewOutput?.on('error', (err: BusinessError) => {
LogUtil.error(TAG, `预览输出错误: ${err.code}`);
});
}
/**
* 设置拍照回调(核心修复)
*/
setPhotoOutputCb(): void {
LogUtil.debug(TAG, '【注册 photoAvailable 回调】');
if (!this.photoOutput) {
LogUtil.debug(TAG, 'photoOutput is null');
return;
}
LogUtil.debug(TAG, '【注册 photoAvailable 回调1】');
this.photoOutput.on('photoAvailable', (err: BusinessError, photo: camera.Photo) => {
LogUtil.debug(TAG, `收到 photoAvailable, photo: ${JSON.stringify(photo)}`);
const imageObj = photo.main;
if (err?.code !== 0) {
LogUtil.error(TAG, `photoAvailable error: ${err.code}`);
this.isCapture = 0;
emitter.emit(EVENT_CAPTURE_FAIL);
imageObj?.release(); // 确保释放资源
return;
}
if (!photo?.main) {
LogUtil.error(TAG, 'photo main is null');
this.isCapture = 0;
emitter.emit(EVENT_CAPTURE_FAIL);
return;
}
LogUtil.debug(TAG, `imageObj.format = ${imageObj.format}`); // 👈 关键日志!
if (imageObj.format !== 2000) { // JPEG格式对应2000
LogUtil.error(TAG, `图像格式异常: 预期JPEG(2000),实际获取${imageObj.format}`);
imageObj.release();
this.isCapture = 0;
emitter.emit(EVENT_CAPTURE_FAIL);
return;
}
// const expectedSize = {width: 1920, height: 1080};
const aw = 640
const ah = 480
if (imageObj.size.width !== aw ||
imageObj.size.height !== ah) {
LogUtil.error(TAG, `尺寸不符: 预期${aw} ${ah},实际${imageObj.size}`);
}
LogUtil.debug(`imageObj.size.width==${imageObj.size.width}`)
LogUtil.debug(`imageObj.size.height==${imageObj.size.height}`)
imageObj.getComponent(image.ComponentType.JPEG, (compErr: BusinessError, component: image.Component) => {
if (compErr?.code !== 0 || !component?.byteBuffer) {
LogUtil.error(TAG, 'getComponent failed or byteBuffer is null');
imageObj.release();
this.isCapture = 0;
emitter.emit(EVENT_CAPTURE_FAIL);
return;
}
const width = imageObj.size.width;
const height = imageObj.size.height;
const pixelMapFormat = this.formatToPixelMapFormatMap.get(imageObj.format) ?? image.PixelMapFormat.NV21;
image.createPixelMap(component.byteBuffer, {
size: { width, height },
srcPixelFormat: pixelMapFormat,
}).then(pixelMap => {
return ImageUtil.savePixelMap(
pixelMap,
` ${this.context?.filesDir!}/takePhoto`,
`img_${new Date().getTime()}.jpg`,
'image/jpeg'
);
}).then(srcPath => {
LogUtil.debug(`获取图片路径===${srcPath}`)
const cutImgPath = libOpencv.cutImg(srcPath);
LogUtil.debug(TAG, `剪裁后图片路径: ${cutImgPath}`);
emitter.emit(EVENT_CAPTURE_SUCCESS, { data: { savaPath: cutImgPath } });
}).catch((e:BusinessError) => {
LogUtil.error(TAG, `保存或剪裁图片失败${e}`);
emitter.emit(EVENT_CAPTURE_FAIL);
}).finally(() => {
imageObj.release();
this.isCapture = 0;
});
});
});
LogUtil.debug(TAG, '【注册 photoAvailable 回调2】');
this.photoOutput?.on('captureStartWithInfo', (err: BusinessError, captureStartInfo: camera.CaptureStartInfo) => {
if (err) {
LogUtil.error(TAG, `拍照开始错误: ${err.code}`);
emitter.emit(EVENT_CAPTURE_FAIL);
return;
}
LogUtil.debug(TAG, `拍照开始, captureId : ${captureStartInfo.captureId}`)
})
LogUtil.debug(TAG, '【注册 photoAvailable 回调3】');
this.photoOutput?.on('captureEnd', (err: BusinessError, captureEndInfo: camera.CaptureEndInfo) => {
if (err !== undefined && err.code !== 0) {
LogUtil.debug(TAG, `captureEnd error code: ${err.code}`)
return
}
LogUtil.debug(TAG, `拍照结束, captureId : ${captureEndInfo.captureId} frameCount: ${captureEndInfo.frameCount}`)
})
//通过注册固定的captureReady回调函数获取监听可拍下一张结果,photoOutput创建成功时即可监听,当下一张可拍时触发,该事件返回结果为下一张可拍的相关信息。
LogUtil.debug(TAG, '【注册 photoAvailable 回调4】');
this.photoOutput?.on('captureReady', (err: BusinessError) => {
if (err !== undefined && err.code !== 0) {
LogUtil.debug(TAG, `captureReady error code: ${err.code}`)
return
}
LogUtil.debug(TAG, `可拍下一张了`)
})
//通过注册固定的error回调函数获取监听拍照输出流的错误结果。回调返回拍照输出接口使用错误时的对应错误码,错误码类型参见Camera错误码。
LogUtil.debug(TAG, '【注册 photoAvailable 回调5】');
this.photoOutput?.on('error', (error: BusinessError) => {
LogUtil.debug(TAG, `拍照输出流 error code: ${error.code}`)
})
}
/**
* 配置会话(如对焦)
*/
configuringSession(): void {
if (!this.session) return;
try {
if (this.session.isFocusModeSupported(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO)) {
this.session.setFocusMode(camera.FocusMode.FOCUS_MODE_CONTINUOUS_AUTO);
LogUtil.debug(TAG, '设置连续自动对焦');
}
} catch (e) {
LogUtil.error(TAG, `设置对焦模式失败: ${JSON.stringify(e)}`);
}
}
/**
* 选择预览配置(示例:选最大分辨率)
*/
getPreviewProfile(profiles: Array<camera.Profile>): camera.Profile {
return profiles[profiles.length - 1]; // 选最后一个(通常最大)
}
/**
* 选择拍照配置(示例:选最大分辨率)
*/
getPhotoProfile(profiles: Array<camera.Profile>): camera.Profile {
// return profiles[profiles.length - 1];
// 优先找 format === 2000 且能输出 JPEG 的(高拍仪通常支持)
// 如果不行,可尝试 format === 35 (YUV) 再转 JPEG(复杂)
const selected = profiles.find(p => p.format === 2000);
// const selected = this.getProfileWithMaxWidth(profiles)
if (!selected) {
LogUtil.error(TAG, "未找到JPEG格式配置");
throw new Error("Unsupported format");
}
// const selected = profiles.find(p =>
// p.format === camera.ImageFormat.JPEG &&
// p.size.width === 1920 &&
// p.size.height === 1080
// );
LogUtil.debug(TAG, `当前拍照配置: ${JSON.stringify(selected)}`);
return selected;
}
getProfileWithMaxWidth(profiles: camera.Profile[]): camera.Profile | null {
if (!profiles || profiles.length === 0) {
return null;
}
return profiles.reduce((prev, curr) => {
// 确保 size 存在且 width 是有效数字(防御性编程)
const prevWidth = prev.size?.width ?? 0;
const currWidth = curr.size?.width ?? 0;
return currWidth > prevWidth ? curr : prev;
});
}
/**
* 拍照
*/
capture(): void {
// if (!this.photoOutput || this.isCapture !== 0) {
if (!this.photoOutput || !this.session || this.isCapture !== 0) {
LogUtil.warn(TAG, '无法拍照:正在拍摄中或 photoOutput 未就绪');
return;
}
this.isCapture = 1;
LogUtil.debug(TAG, '开始拍照');
const settings: camera.PhotoCaptureSetting = {
quality: camera.QualityLevel.QUALITY_LEVEL_LOW,
rotation: camera.ImageRotation.ROTATION_0,
};
try {
this.photoOutput.capture(settings, (err: BusinessError) => {
if (err) {
LogUtil.error(TAG, `capture 回调错误: ${err.code}`);
this.isCapture = 0;
emitter.emit(EVENT_CAPTURE_FAIL);
return; // 添加return避免继续执行
}
LogUtil.debug("拍照返回数据")
console.info('Callback invoked to indicate the photo capture request success.');
LogUtil.debug(TAG, `拍照请求已接受,等待photoAvailable事件`);
});
} catch (error) {
LogUtil.error(TAG, `capture 调用异常: ${JSON.stringify(error)}`);
this.isCapture = 0;
emitter.emit(EVENT_CAPTURE_FAIL);
}
}
/**
* 释放相机资源
*/
async releaseCamera(): Promise<void> {
LogUtil.debug(TAG, '释放相机资源');
try {
await this.session?.stop();
await this.cameraInput?.close();
await this.previewOutput?.release();
await this.photoOutput?.release(); // ✅ 释放 PhotoOutput
await this.session?.release();
this.isCapture = 0;
LogUtil.debug(TAG, '相机资源释放完成');
} catch (e) {
LogUtil.error(TAG, `释放相机出错: ${JSON.stringify(e)}`);
}
}
}
function callback(err: undefined, BusinessError: undefined, photo: undefined, Photo: undefined) {
throw new Error('Function not implemented.');
}
```
3. 运行结果、错误截图 运行结果 就是没有反应 日志如下
02-02 14:30:25.324 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView usb deviceName:1-1, manufacturerName: xHCI Host Controller vendorId: 7531 productId: 2
02-02 14:30:25.324 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView usb deviceName:1-2, manufacturerName: USB2.0 HUB vendorId: 6790 productId: 32926
02-02 14:30:25.324 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView usb deviceName:1-3, manufacturerName: Fic Video vendorId: 10071 productId: 5123
02-02 14:30:25.325 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView usb deviceName:1-4, manufacturerName: ILITEK-TP vendorId: 8746 productId: 1
02-02 14:30:25.325 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView usb deviceName:1-5, manufacturerName: PROTOCOL vendorId: 1155 productId: 19523
02-02 14:30:25.325 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView usb deviceName:1-6, manufacturerName: USB Serial vendorId: 6790 productId: 29987
02-02 14:30:25.325 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView usb deviceName:2-1, manufacturerName: xHCI Host Controller vendorId: 7531 productId: 3
02-02 14:30:25.338 27711-27711 A03d00/JSAPP com.nhiig...ion.hmos D onPageShow
02-02 14:30:25.338 27711-27711 A03d00/JSAPP com.nhiig...ion.hmos D this.articlesNumList长度===1
02-02 14:30:25.338 27711-27711 A03d00/JSAPP com.nhiig...ion.hmos D this.articlesNumList长度===1
02-02 14:30:25.341 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 响应成功结果:{"status":0,"msg":"ok","data":{"chargeType":2,"paperCardPrice":50,"printPrice":50,"judgePrice":1000}}
02-02 14:30:25.342 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView usb device request right result: true
02-02 14:30:25.342 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView productName: Fic Video
02-02 14:30:25.342 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView getIsInitCamera: true
02-02 14:30:25.388 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView XComponent 的宽度:722.6666666666666
02-02 14:30:25.388 27711-27711 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D TakePhotoView XComponent 的高度:542
02-02 14:30:25.416 27711-29111 A03200/MY_TAG com.nhiig...ion.hmos I 🔍 Init: 开始初始化 MuPDF 上下文
02-02 14:30:25.418 27711-29111 A03200/MY_TAG com.nhiig...ion.hmos I 🔍 Init: MuPDF context created successfully
02-02 14:30:25.418 27711-29111 A03200/MY_TAG com.nhiig...ion.hmos I 🔍 Init: Document handlers registered
02-02 14:30:25.418 27711-29111 A03200/MY_TAG com.nhiig...ion.hmos I 🔍 Init: Module initialized successfully
02-02 14:30:25.431 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraWorker 收到消息 type:initCamera
02-02 14:30:25.431 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 messageInfo.surfaceId===3345779523643
02-02 14:30:25.431 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 调用 initCamera
02-02 14:30:25.431 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 调用 getUsbCamera
02-02 14:30:25.457 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 使用相机: ID= lcam001, 连接类型= 0
02-02 14:30:25.470 1583-1583 A0001a/SystemUI_Default com.ohos.systemui I PrivacyIndicatorViewModel --> permission state changed.
02-02 14:30:25.470 1583-1583 A0001a/SystemUI_Default com.ohos.systemui I PrivacyIndicatorViewModel --> indicator 1 isShow: true
02-02 14:30:25.517 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager previewProfiles: [{"format":3,"size":{"width":640,"height":480}},{"format":3,"size":{"width":1280,"height":720}},{"format":3,"size":{"width":1280,"height":960}},{"format":3,"size":{"width":1920,"height":1080}}]
02-02 14:30:25.517 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager photoProfiles: [{"format":2000,"size":{"width":640,"height":480}},{"format":2000,"size":{"width":1280,"height":960}},{"format":2000,"size":{"width":1920,"height":1080}}]
02-02 14:30:25.517 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 当前拍照配置: {"format":2000,"size":{"width":640,"height":480}}
02-02 14:30:25.523 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 【注册 photoAvailable 回调】
02-02 14:30:25.523 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 【注册 photoAvailable 回调1】
02-02 14:30:25.524 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 【注册 photoAvailable 回调2】
02-02 14:30:25.525 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 【注册 photoAvailable 回调3】
02-02 14:30:25.526 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 【注册 photoAvailable 回调4】
02-02 14:30:25.526 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 【注册 photoAvailable 回调5】
02-02 14:30:25.537 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 添加输出流(预览流)成功
02-02 14:30:25.539 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 添加输出流(拍照流)成功
02-02 14:30:25.556 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager Display rotation: 0
02-02 14:30:25.636 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager this.session: [object Object]
02-02 14:30:25.641 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 设置连续自动对焦
02-02 14:30:25.641 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 相机初始化成功
02-02 14:30:25.649 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 预览帧开始
02-02 14:30:28.420 27711-27711 A00000/AsyncMqtt com.nhiig...ion.hmos D AsyncMqtt IsConnected Start
02-02 14:30:28.863 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraWorker 收到消息 type:capture
02-02 14:30:28.864 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 开始拍照
02-02 14:30:28.878 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 CameraManager 拍照开始, captureId : 18
02-02 14:30:28.896 27711-29111 A00000/HarmonyUtilsLog com.nhiig...ion.hmos D 线程: 29111 拍照返回数据
02-02 14:30:28.896 27711-29111 A03d00/JSAPP com.nhiig...ion.hmos I Callback invoked to indicate the photo capture request success.
4. 我尝试过的解决方法和结果
配置参数 和 修改相机的配置 调整预览的尺寸等 都不行
5. 我想要达到的结果
当点击拍照的时候 可以触发 photoavailable 获取图像信息 完成拍照的信息
### 【运行环境】
硬件:` `rk3576 ` `
ROM版本:openharmony-6.0.0.47
DevEvoStudio版本:DevEco Studio 6.0.2 Release
SDK版本:HarmonyOS 6.0.2 Release SDK,原样包含OpenHarmony SDK Ohos_sdk_public 6.0.2.130 (API Version 22 Release)
[/md]
作者:
星辰大海
时间:
6 天前
你好,请参考这个接口:
注册监听拍照返回照片上报事件。使用callback异步回调。
欢迎光临 OpenHarmony开发者论坛 (https://forums.openharmony.cn/)
Powered by Discuz! X3.5