diff --git a/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets b/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets index 4baaa6bba847d27aace422e077ff9b62e205142c..9b034a0188e0db43dd60ee4afc39193998abcc43 100644 --- a/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets +++ b/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets @@ -17,18 +17,18 @@ * FAQ:base64字符串如何转为图片并保存 */ -// DocsCode 1 +// [Start Base64ImageConverter] import { buffer } from '@kit.ArkTS'; import { fileIo } from '@kit.CoreFileKit'; import { common } from '@kit.AbilityKit'; import { fileUri } from "@kit.CoreFileKit"; import { hilog } from '@kit.PerformanceAnalysisKit'; -// 工具类中:在EntryAbility中获取Context后保存至AppStorage,然后在工具类中使用AppStorage获取 +// In the utility class, retrieve the Context from the Entry Ability and save it to AppStore, then use AppStore to retrieve it in the utility class let context = AppStorage.get("context") as UIContext; let filesDir = context.getHostContext()!.filesDir; -// data为需要转换的base64字符串,返回沙箱路径uri +// Data is the base64 string that needs to be converted, and returns the sandbox path URI export async function writeFile(data: string): Promise { let uri = '' try { @@ -49,4 +49,4 @@ export async function writeFile(data: string): Promise { } return uri; } -// DocsCode 1 \ No newline at end of file +// [End Base64ImageConverter] \ No newline at end of file diff --git a/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets b/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets index 75ebf704d93c1590d26b8231cfcf1b451ac7cabe..43f85ca1a8b71342ad3796b700f2a2a8e38c58e2 100644 --- a/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets +++ b/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets @@ -17,7 +17,7 @@ * FAQ:关于导入图片的使用权限和问题 */ -// DocsCode 1 +// [Start ImportedImagesPermissionsAndIssues] import { BusinessError } from '@kit.BasicServicesKit'; import { fileIo } from '@kit.CoreFileKit'; import { common } from '@kit.AbilityKit'; @@ -27,8 +27,8 @@ let context = getContext(this) as common.UIAbilityContext; let filesDir = context.filesDir; function SavePictureToContext(){ const photoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); - photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // 过滤选择媒体文件类型为IMAGE - photoSelectOptions.maxSelectNumber = 5; // 选择媒体文件的最大数目 + photoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; // Filter and select media file type as IMAGE + photoSelectOptions.maxSelectNumber = 5; // Select the maximum number of media files let uris: Array = []; const photoViewPicker = new photoAccessHelper.PhotoViewPicker(); photoViewPicker.select(photoSelectOptions).then((photoSelectResult: photoAccessHelper.PhotoSelectResult) => { @@ -44,7 +44,7 @@ function SavePictureToContext(){ fileIo.copyFileSync(fd, filesDir + '/test2.jpg') let file2 = fileIo.openSync(filesDir + '/test2.jpg', fileIo.OpenMode.READ_ONLY ); let file3 = fileIo.openSync(filesDir + '/test3.jpg', fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); - // 将fd传入后,C端即可进行调用 + // After passing fd in, the C end can call it // ReadFile(file2.fd,file3.fd) } -// DocsCode 1 \ No newline at end of file +// [End ImportedImagesPermissionsAndIssues] \ No newline at end of file diff --git a/MediaLibraryKit/entry/src/main/ets/pages/SelectFileSavePath.ets b/MediaLibraryKit/entry/src/main/ets/pages/SelectFileSavePath.ets index 255a7546c1f32f2f228b9c4766d483c4d815fc73..b3dadfdd6ec7619ef79509ddeac04b3107fb00fa 100644 --- a/MediaLibraryKit/entry/src/main/ets/pages/SelectFileSavePath.ets +++ b/MediaLibraryKit/entry/src/main/ets/pages/SelectFileSavePath.ets @@ -17,7 +17,7 @@ * FAQ:如何选择文件保存路径 */ -// DocsCode 1 +// [Start SelectFileSavePath] import { photoAccessHelper } from '@kit.MediaLibraryKit'; import { fileIo } from '@kit.CoreFileKit'; @@ -33,20 +33,20 @@ struct WebComponent { SaveButton().onClick(async (event: ClickEvent, result: SaveButtonOnClickResult) => { if (result === SaveButtonOnClickResult.SUCCESS) { try { - const context = this.getUIContext().getHostContext(); + const context = this.getUIContext().getHostContext()!; let helper = photoAccessHelper.getPhotoAccessHelper(context); - // onClick触发后10秒内通过createAsset接口创建图片文件,10秒后createAsset权限收回。 + // Create image files through the Create Asset interface within 10 seconds after the nClick trigger, and revoke the Create Asset permission after 10 seconds. let uri = await helper.createAsset(photoAccessHelper.PhotoType.IMAGE, 'jpg'); - // 使用uri打开文件,可以持续写入内容,写入过程不受时间限制 + // Using URI to open files allows for continuous writing of content without time constraints during the writing process let file = await fileIo.open(uri, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); try { context.resourceManager.getMediaContent($r('app.media.startIcon').id, 0) .then(async value => { let media = value.buffer; - // 写到媒体库文件中 + // Write to the media library file await fileIo.write(file.fd, media); await fileIo.close(file.fd); - this.getUIContext().showAlertDialog({ message: '已保存至相册!' }); + this.getUIContext().showAlertDialog({ message: 'Saved to album!' }); }); } catch (err) { console.error('error is ' + JSON.stringify(err)) @@ -55,7 +55,7 @@ struct WebComponent { console.error('error is ' + JSON.stringify(error)); } } else { - this.getUIContext().showAlertDialog({ message: '设置权限失败' }) + this.getUIContext().showAlertDialog({ message: 'Failed to set permissions' }) } }) } @@ -64,4 +64,4 @@ struct WebComponent { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End SelectFileSavePath] \ No newline at end of file diff --git a/MediaLibraryKit/entry/src/main/resources/base/profile/main_pages.json b/MediaLibraryKit/entry/src/main/resources/base/profile/main_pages.json index d798da48122b66adbec51d80c0220172e0c6b27b..55c3f007f87b7ce5206d325f968cc56f2f79441f 100644 --- a/MediaLibraryKit/entry/src/main/resources/base/profile/main_pages.json +++ b/MediaLibraryKit/entry/src/main/resources/base/profile/main_pages.json @@ -1,6 +1,5 @@ { "src": [ - "pages/Index", - "pages/ImportedImagesPermissionsAndIssues" + "pages/Index" ] } \ No newline at end of file