参考代码:
XComponent组件:
createXComponent(){
XComponent({
id: 'componentId',
type: 'surface',
controller: this.mXComponentController
}) .gesture(
PinchGesture({ fingers: 2 })
.onActionUpdate((event: GestureEvent) => {
if (event && !this.isStabilization) {
this.zoom = this.zoom * ((event.scale - 1) * 0.07 + 1)
this.isShowZoom = true
if (this.zoom > zoomRatioRange[1]) {
this.zoom = zoomRatioRange[1]
} else if (this.zoom < zoomRatioRange[0]) {
this.zoom = zoomRatioRange[0]
}
if (this.isPhoto) {
CameraShooter.setPhotoZoom(this.zoom);
} else {
setVideoZoom(this.zoom);
}
}
})
.onActionEnd(() => {
this.isShowZoom = false
})
)
.onLoad(async () => {
this.mXComponentController.setXComponentSurfaceSize({
surfaceWidth: previewSize.height,
surfaceHeight: previewSize.width
});
surfaceId = this.mXComponentController.getXComponentSurfaceId();
})
.height(CameraConstants.SURFACE_HEIGHT)
.width(CameraConstants.FULL_SCREEN)
}
let previewSize: camera.Size = {
width: CameraConstants.PREVIEW_WIDTH,
height: CameraConstants.PREVIEW_HEIGHT
};
/**
* camera preview size
*/
static readonly PREVIEW_WIDTH: number = 2592;
/**
* camera preview size
*/
static readonly PREVIEW_HEIGHT: number = 1944;
static readonly SURFACE_HEIGHT: string = '1650px';
static readonly FULL_SCREEN: string = '100%';
将参数改为demo里的相机参数: