diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index fea4cf71da0865502cbe6c1dda2c1d8d60a1b141..adb9ff3c0d678b84f0d78d2762acb3512cbaf886 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);