From ffa045463da89ef623b4f721e35c2013809ed25a Mon Sep 17 00:00:00 2001 From: hdw Date: Tue, 13 May 2025 16:52:09 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=20=E5=BA=9F=E5=BC=83api=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- entry/src/main/ets/pages/Index.ets | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index fea4cf7..adb9ff3 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -27,8 +27,8 @@ const TAG = 'IMAGE_APP'; @Entry @Component struct Index { - @State path: string = getContext(this).filesDir + '/image.jpg'; - @State pixelMapPath: string = getContext(this).filesDir + '/pixelMap.jpg'; + @State path: string = this.getUIContext().getHostContext()!.filesDir + '/image.jpg'; + @State pixelMapPath: string = this.getUIContext().getHostContext()!.filesDir + '/pixelMap.jpg'; @State imageUri: string | undefined = undefined; @State imageSource: image.ImageSource | undefined = undefined; @State pixelMap: image.PixelMap | undefined = undefined; @@ -80,7 +80,7 @@ struct Index { try { let pickerProfile: cameraPicker.PickerProfile = { cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK }; - let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(getContext(this), + let pickerResult: cameraPicker.PickerResult = await cameraPicker.pick(this.getUIContext().getHostContext()!, [cameraPicker.PickerMediaType.PHOTO], pickerProfile); this.imageUri = pickerResult.resultUri ? pickerResult.resultUri : this.imageUri; hilog.info(0x0000, TAG, 'cameraPicker.pick succeed, uri: ' + JSON.stringify(pickerResult)); @@ -98,7 +98,7 @@ struct Index { try { let documentSelectOptions = new picker.DocumentSelectOptions(); documentSelectOptions.maxSelectNumber = 1; - let documentPicker = new picker.DocumentViewPicker(getContext(this)); + let documentPicker = new picker.DocumentViewPicker(this.getUIContext().getHostContext()!); documentPicker.select(documentSelectOptions).then((documentSelectResult: Array) => { hilog.info(0x0000, TAG, 'DocumentViewPicker.select succeed, uri: ' + JSON.stringify(documentSelectResult)); @@ -209,7 +209,7 @@ struct Index { if (result === SaveButtonOnClickResult.SUCCESS) { try { await pixelMap2File(this.pixelMap, this.path); - let context = getContext(); + let context = this.getUIContext().getHostContext()!; let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createImageAssetRequest(context, this.path); -- Gitee