async aboutToAppear(): Promise<void> {
const initResult = await subjectSegmentation.init();
hilog.info(0x0000, 'subjectSegmentationSample', `Subject segmentation initialization result:${initResult}`);
}
async aboutToDisappear(): Promise<void> {
await subjectSegmentation.release();
hilog.info(0x0000, 'subjectSegmentationSample', 'Subject segmentation released successfully');
}
private async selectImage() {
let uri = await this.openPhoto()
if (uri === undefined) {
hilog.error(0x0000, TAG, "uri is undefined");
}
this.loadImage(uri);
}
private openPhoto(): Promise<Array<string>> {
return new Promise<Array<string>>((resolve, reject) => {
let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions();
PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE;
PhotoSelectOptions.maxSelectNumber = 1;
let photoPicker: photoAccessHelper.PhotoViewPicker = new photoAccessHelper.PhotoViewPicker();
hilog.info(0x0000, TAG, 'PhotoViewPicker.select successfully, PhotoSelectResult uri: ');
photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult) => {
hilog.info(0x0000, TAG, `PhotoViewPicker.select successfully, PhotoSelectResult uri: ${PhotoSelectResult.photoUris}`);
resolve(PhotoSelectResult.photoUris)
}).catch((err: BusinessError) => {
hilog.error(0x0000, TAG, `PhotoViewPicker.select failed with errCode: ${err.code}, errMessage: ${err.message}`);
reject();
});
})
}
private loadImage(names: string[]) {
setTimeout(async () => {
let imageSource: image.ImageSource | undefined = undefined
let fileSource = await fileIo.open(names[0], fileIo.OpenMode.READ_ONLY)
imageSource = image.createImageSource(fileSource.fd)
this.chooseImage = await imageSource.createPixelMap()
hilog.info(0x0000, TAG, `this.chooseImage===${this.chooseImage}`);
}, 100
)
}
评论