From 890e607906920e2ac75da9a94251eb716a9ee76c Mon Sep 17 00:00:00 2001 From: kuangning <2540487435@qq.com> Date: Thu, 15 May 2025 18:48:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?MediaLibraryKit=E6=B7=BB=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/pages/Base64ImageConverter.ets | 4 ++-- .../main/ets/pages/ImportedImagesPermissionsAndIssues.ets | 4 ++-- .../entry/src/main/ets/pages/SelectFileSavePath.ets | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets b/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets index 4baaa6b..76d4eeb 100644 --- a/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets +++ b/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets @@ -17,7 +17,7 @@ * FAQ:base64字符串如何转为图片并保存 */ -// DocsCode 1 +// [Start Base64ImageConverter] import { buffer } from '@kit.ArkTS'; import { fileIo } from '@kit.CoreFileKit'; import { common } from '@kit.AbilityKit'; @@ -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 75ebf70..698d356 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'; @@ -47,4 +47,4 @@ function SavePictureToContext(){ // 将fd传入后,C端即可进行调用 // 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 255a754..cd1fbed 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,7 +33,7 @@ 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权限收回。 let uri = await helper.createAsset(photoAccessHelper.PhotoType.IMAGE, 'jpg'); @@ -64,4 +64,4 @@ struct WebComponent { .height('100%') } } -// DocsCode 1 \ No newline at end of file +// [End SelectFileSavePath] \ No newline at end of file -- Gitee From 37a90987edb14d57ca602a90cee2449feade1610 Mon Sep 17 00:00:00 2001 From: kuangning <2540487435@qq.com> Date: Thu, 15 May 2025 19:03:32 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=88=A0=E9=99=A4profile=E4=B8=AD=E5=A4=9A?= =?UTF-8?q?=E4=BD=99=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/resources/base/profile/main_pages.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 d798da4..55c3f00 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 -- Gitee From 04e1b9f9f32279dcceaf7368ef91ae3ce8cbb2c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E9=93=83?= <2540487435@qq.com> Date: Sat, 17 May 2025 06:30:22 +0000 Subject: [PATCH 3/3] =?UTF-8?q?MediaLibraryKit=E4=BF=AE=E6=94=B9=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E4=B8=BA=E8=8B=B1=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 风铃 <2540487435@qq.com> --- .../entry/src/main/ets/pages/Base64ImageConverter.ets | 4 ++-- .../ets/pages/ImportedImagesPermissionsAndIssues.ets | 6 +++--- .../entry/src/main/ets/pages/SelectFileSavePath.ets | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets b/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets index 76d4eeb..9b034a0 100644 --- a/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets +++ b/MediaLibraryKit/entry/src/main/ets/pages/Base64ImageConverter.ets @@ -24,11 +24,11 @@ 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 { diff --git a/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets b/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets index 698d356..43f85ca 100644 --- a/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets +++ b/MediaLibraryKit/entry/src/main/ets/pages/ImportedImagesPermissionsAndIssues.ets @@ -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) } // [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 cd1fbed..b3dadfd 100644 --- a/MediaLibraryKit/entry/src/main/ets/pages/SelectFileSavePath.ets +++ b/MediaLibraryKit/entry/src/main/ets/pages/SelectFileSavePath.ets @@ -35,18 +35,18 @@ struct WebComponent { try { 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' }) } }) } -- Gitee