鸿蒙可以通过分布式能力实现跨设备协同import { createCollaborationServiceMenuItems, CollaborationServiceStateDialog, CollaborationServiceFilter } from '@kit.ServiceCollaborationKit'; import { image } from '@kit.ImageKit'; import { hilog } from '@kit.PerformanceAnalysisKit'; @Entry @Component struct Index { @State picture: PixelMap | undefined = undefined; @Builder MyTestMenu() { Menu() { createCollaborationServiceMenuItems([CollaborationServiceFilter.ALL], 30) } } build() { Column({ space: 20 }) { CollaborationServiceStateDialog({ onState: (stateCode: number, bufferType: string, buffer: ArrayBuffer): void => this.doInsertPicture(stateCode, bufferType, buffer) }) Button('使用远端设备进行拍照') .type(ButtonType.Normal) .borderRadius(10) .bindMenu(this.MyTestMenu) if (this.picture) { Image(this.picture) .borderStyle(BorderStyle.Dotted) .borderWidth(1) .objectFit(ImageFit.Contain) .height('80%') .onComplete((event) => { if (event != undefined) { hilog.info(0, "MEMOMOCK", "onComplete " + event.loadingStatus) } }) } } .padding(20) .width('100%') .alignItems(HorizontalAlign.Center) } doInsertPicture(stateCode: number, bufferType: string, buffer: ArrayBuffer): void { if (stateCode != 0) { return } if (bufferType == "general.image") { let imageSource = image.createImageSource(buffer) imageSource.createPixelMap().then((pixelMap) => { this.picture = pixelMap; }) } } }
鸿蒙可以通过分布式能力实现跨设备协同