From 51cb3a7a8f33828252881cb2c9e6883ed3871b55 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 31 Aug 2024 16:30:08 +0800 Subject: [PATCH] =?utf8?q?=E4=BD=BF=E7=94=A8LoadSingleRes=E4=B8=8EUnloadSi?= =?utf8?q?ngleRes=E8=BF=9B=E8=A1=8C=E5=8A=A8=E7=94=BB=E8=B5=84=E6=BA=90?= =?utf8?q?=E5=8A=A0=E8=BD=BD=E9=87=8A=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../uicomponents/UIComponents.cpp | 25 ++++++++++++++----- .../uicomponents/UIComponents.h | 5 ++-- .../takephotos/include/TakephotosView.h | 8 +++--- .../takephotos/src/TakephotosView.cpp | 18 ++++++------- .../training_card/include/TraingCardView.h | 4 +-- .../training_card/src/TraingCardView.cpp | 12 ++++----- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index 6f248864e..9eecf69de 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -436,7 +436,7 @@ namespace OHOS { InitLabel(label, x, y, width, height, viewId, text, fontName, fontSize); } - void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *&imageAnimatorInfo, const char **imagePaths, int numFrames, int left, int top, int width, int height, const char *viewId, int time) + void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *&imageAnimatorInfo, const ImageInfo **imageInfo, int numFrames, int left, int top, int width, int height, const char *viewId, int time) { if (imageAnimator == nullptr) { @@ -451,12 +451,12 @@ namespace OHOS imageAnimatorInfo = new ImageAnimatorInfo[numFrames]; for (int i = 0; i < numFrames; i++) { - imageAnimatorInfo[i].imagePath = imagePaths[i]; + imageAnimatorInfo[i].imageInfo = imageInfo[i]; imageAnimatorInfo[i].pos.x = left; imageAnimatorInfo[i].pos.y = top; imageAnimatorInfo[i].width = width; imageAnimatorInfo[i].height = height; - imageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + imageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; } imageAnimator->SetImageAnimatorSrc(imageAnimatorInfo, numFrames, time); // 200 is the default delay time @@ -698,7 +698,22 @@ namespace OHOS } return imageinfo_array; } - + /** + * 释放创建的图片路径数组 + * @param imagePaths 包含图片路径的数组 + * @param numImages 图片文件的数量 + */ + void FreeImageInfoArray(const ImageInfo **imagePaths, int numImages) + { + if (imagePaths != nullptr) + { + for (int i = 0; i < numImages; i++) + { + ImageCacheManager::GetInstance().UnloadSingleRes((char *)imagePaths[i]); + } + UIFree(const_cast(imagePaths)); // 释放整个数组 + } + } void FreeImageInfoArray(const ImageInfo **array, const char *basePath, int numImages, const char *fileExtension) { for (int i = 0; i < numImages; i++) @@ -745,7 +760,6 @@ namespace OHOS } return imagePaths; } - /** * 释放创建的图片路径数组 * @param imagePaths 包含图片路径的数组 @@ -762,7 +776,6 @@ namespace OHOS UIFree(const_cast(imagePaths)); // 释放整个数组 } } - /*解析动画资源数组 imageche*/ std::vector AnalysisArray(const char *filename, uint32_t startId, uint32_t lastId) { diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index 016b28532..1b515ed3e 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -218,8 +218,9 @@ namespace OHOS * @param imagePaths 要释放的图像路径数组。 * @param numImages 数组长度。 */ - void FreeImagePathsArray(const char **imagePaths, int numImages); + void FreeImageInfoArray(const ImageInfo **imagePaths, int numImages); + void FreeImagePathsArray(const char **imagePaths, int numImages); /** * @brief 初始化 UIImageAnimatorView,并设置为 GIF 动画。 * @@ -228,7 +229,7 @@ namespace OHOS * @param config 动画相关的配置(包括路径和帧信息)。 * @param generalConfig 视图的基本配置(位置、大小、视图 ID 等)。 */ - void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *&imageAnimatorInfo, const ImageAnimatorConfig &config, const GeneralConfig &generalConfig); + void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *&imageAnimatorInfo, const ImageInfo **imageInfo, int numFrames, int left, int top, int width, int height, const char *viewId, int time); /** * @brief 释放 UIImageAnimatorView 的资源。 diff --git a/code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosView.h b/code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosView.h index 319e10a8b..e15d0b176 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosView.h @@ -84,12 +84,12 @@ namespace OHOS bool viewiInitStatus{false}; - std::string creambasePath; - const char **creamimagePaths; + std::string creambasePath = "/user/res/takephotos/cream/"; + const ImageInfo **creamimageInfos; ImageAnimatorInfo *creamimageAnimatorInfo{nullptr}; - std::string smilebasePath; - const char **smileimagePaths; + std::string smilebasePath = "/user/res/takephotos/cream/"; + const ImageInfo **smileimageInfos; ImageAnimatorInfo *smileimageAnimatorInfo{nullptr}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp b/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp index f9ed31a7e..e998433ce 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp @@ -31,10 +31,10 @@ namespace OHOS // DeInit(); creamAnimator->Stop(); smileAnimator->Stop(); - FreeImagePathsArray(creamimagePaths, 50); - FreeImagePathsArray(smileimagePaths, 27); - ReleaseImageAnimatorSource(creamimageAnimatorInfo,50); - ReleaseImageAnimatorSource(smileimageAnimatorInfo,27); + FreeImageInfoArray(creamimageInfos, creambasePath.c_str(), 50); + FreeImageInfoArray(smileimageInfos, smilebasePath.c_str(), 50); + ReleaseImageAnimatorSource(creamimageAnimatorInfo, 50); + ReleaseImageAnimatorSource(smileimageAnimatorInfo, 50); UIViewGroup *tmpGroup = dynamic_cast(container_); UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); @@ -146,9 +146,8 @@ namespace OHOS buttongo->SetOnClickListener(static_cast(TakephotosPresenter::GetInstance())); // 初始化图片数组以及动画 - creambasePath = "/user/res/takephotos/cream/"; - creamimagePaths = CreateImagePathsArray(creambasePath.c_str(), 50); - InitImageAnimatorSource(creamAnimator, creamimageAnimatorInfo, creamimagePaths, 50, 163, 103, 140, 140, "imageAnimator", 100); + creamimageInfos = CreateImageInfoArray(creambasePath.c_str(), 50); + InitImageAnimatorSource(creamAnimator, creamimageAnimatorInfo, creamimageInfos, 50, 163, 103, 140, 140, "imageAnimator", 100); creamView->Add(creamAnimator); creamView->Add(labeltitle_); @@ -197,9 +196,8 @@ namespace OHOS buttontake->SetOnClickListener(static_cast(TakephotosPresenter::GetInstance())); // 初始化图片数组以及动画 {修改为统一动画} - smilebasePath = "/user/res/takephotos/cream/"; - smileimagePaths = CreateImagePathsArray(smilebasePath.c_str(), 27); - InitImageAnimatorSource(smileAnimator, smileimageAnimatorInfo, smileimagePaths, 27, 163, 140, 140, 140, "imageAnimator", 100); + smileimageInfos = CreateImageInfoArray(smilebasePath.c_str(), 50); + InitImageAnimatorSource(smileAnimator, smileimageAnimatorInfo, smileimageInfos, 50, 163, 140, 140, 140, "imageAnimator", 100); takeView->Add(smileAnimator); takeView->Add(labeltake_); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h index bf3e671fb..12c67b4b6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h @@ -135,8 +135,8 @@ namespace OHOS bool viewiInitStatus{false}; bool momentumFlag{false}; - std::string winbasePath; - const char **winimagePaths; + std::string winbasePath = "/user/res/Training/training_GIF/win/"; + const ImageInfo **winimageInfos; ImageAnimatorInfo *winimageAnimatorInfo{nullptr}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp index c34330faf..ee3da6802 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp @@ -87,7 +87,9 @@ namespace OHOS TraingCardView::~TraingCardView() { - FreeImagePathsArray(winimagePaths, 94); + imageAnimator->Stop(); + FreeImageInfoArray(winimageInfos, winbasePath.c_str(), 94); + ReleaseImageAnimatorSource(winimageAnimatorInfo, 94); DeInit(); g_pTraingCardView = nullptr; @@ -181,9 +183,6 @@ namespace OHOS buttonnote_ = nullptr; /*动画*/ - FreeImagePathsArray(winimagePaths, 94); - ReleaseImageAnimatorSource(winimageAnimatorInfo,94); - imageAnimator->Stop(); delete imageAnimator; imageAnimator = nullptr; @@ -490,9 +489,8 @@ namespace OHOS getView->Add(labeltag); // 初始化图片数组以及动画 - winbasePath = "/user/res/Training/training_GIF/win/"; - winimagePaths = CreateImagePathsArray(winbasePath.c_str(), 94); - InitImageAnimatorSource(imageAnimator, winimageAnimatorInfo, winimagePaths, 94, 173, 100, 120, 120, "imageAnimator1", 10); + winimageInfos = CreateImageInfoArray(winbasePath.c_str(), 94); + InitImageAnimatorSource(imageAnimator, winimageAnimatorInfo, winimageInfos, 94, 173, 100, 120, 120, "imageAnimator1", 10); getView->Add(imageAnimator); } -- 2.17.1