{
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)
{
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
}
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<const ImageInfo **>(imagePaths)); // 释放整个数组
+ }
+ }
void FreeImageInfoArray(const ImageInfo **array, const char *basePath, int numImages, const char *fileExtension)
{
for (int i = 0; i < numImages; i++)
}
return imagePaths;
}
-
/**
* 释放创建的图片路径数组
* @param imagePaths 包含图片路径的数组
UIFree(const_cast<const char **>(imagePaths)); // 释放整个数组
}
}
-
/*解析动画资源数组 imageche*/
std::vector<ImageInfo *> AnalysisArray(const char *filename, uint32_t startId, uint32_t lastId)
{
* @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 动画。
*
* @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 的资源。
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
// 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<UIViewGroup *>(container_);
UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
buttongo->SetOnClickListener(static_cast<UIView::OnClickListener *>(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_);
buttontake->SetOnClickListener(static_cast<UIView::OnClickListener *>(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_);
bool viewiInitStatus{false};\r
bool momentumFlag{false};\r
\r
- std::string winbasePath;\r
- const char **winimagePaths;\r
+ std::string winbasePath = "/user/res/Training/training_GIF/win/";\r
+ const ImageInfo **winimageInfos;\r
ImageAnimatorInfo *winimageAnimatorInfo{nullptr};\r
};\r
} // namespace OHOS\r
\r
TraingCardView::~TraingCardView()\r
{\r
- FreeImagePathsArray(winimagePaths, 94);\r
+ imageAnimator->Stop();\r
+ FreeImageInfoArray(winimageInfos, winbasePath.c_str(), 94);\r
+ ReleaseImageAnimatorSource(winimageAnimatorInfo, 94);\r
DeInit();\r
\r
g_pTraingCardView = nullptr;\r
buttonnote_ = nullptr;\r
\r
/*动画*/\r
- FreeImagePathsArray(winimagePaths, 94);\r
- ReleaseImageAnimatorSource(winimageAnimatorInfo,94);\r
- imageAnimator->Stop();\r
delete imageAnimator;\r
imageAnimator = nullptr;\r
\r
getView->Add(labeltag);\r
\r
// 初始化图片数组以及动画\r
- winbasePath = "/user/res/Training/training_GIF/win/";\r
- winimagePaths = CreateImagePathsArray(winbasePath.c_str(), 94);\r
- InitImageAnimatorSource(imageAnimator, winimageAnimatorInfo, winimagePaths, 94, 173, 100, 120, 120, "imageAnimator1", 10);\r
+ winimageInfos = CreateImageInfoArray(winbasePath.c_str(), 94);\r
+ InitImageAnimatorSource(imageAnimator, winimageAnimatorInfo, winimageInfos, 94, 173, 100, 120, 120, "imageAnimator1", 10);\r
getView->Add(imageAnimator);\r
}\r
\r