From 45fc9c4e128a2c7987c0f60434178c0b125ab7fc Mon Sep 17 00:00:00 2001 From: xing-tai-zhang Date: Wed, 20 Jul 2022 15:27:59 +0800 Subject: [PATCH] Description: Fix the problem that the image does not display after inputting the correct path information IssueNo: https://gitee.com/openharmony/graphic_ui/issues/I5HZE8 Feature or Bugfix: Bugfix Binary Source:No Signed-off-by: xing-tai-zhang --- frameworks/common/image.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/frameworks/common/image.cpp b/frameworks/common/image.cpp index 6cde2bc..ad2ee86 100644 --- a/frameworks/common/image.cpp +++ b/frameworks/common/image.cpp @@ -132,24 +132,36 @@ bool Image::SetLiteSrc(const char* src) return false; } - size_t strLen = strlen(src) + 1; + const char* suffixName = ".bin"; + size_t strLen = strlen(src) + strlen(suffixName) + 1; char* imagePath = static_cast(UIMalloc(static_cast(strLen))); if (imagePath == nullptr) { return false; } if (IsImgValid(ptr)) { - const char* suffixName = "bin"; if (memcpy_s(imagePath, strLen, src, strLen) != EOK) { UIFree(reinterpret_cast(imagePath)); imagePath = nullptr; return false; } - (ptr - src + imagePath)[1] = '\0'; // remove suffix - if (strcat_s(imagePath, strLen, suffixName) != EOK) { + if (strcat_s(imagePath, strLen, suffixName) != EOK) { // The format is xxx.xxx.bin UIFree(reinterpret_cast(imagePath)); imagePath = nullptr; return false; } + if (access(imagePath, F_OK) != EOK) { // Check whether the xxx.xxx.bin file exists + if (memcpy_s(imagePath, strLen, src, strLen) != EOK) { + UIFree(reinterpret_cast(imagePath)); + imagePath = nullptr; + return false; + } + (ptr - src + imagePath)[0] = '\0'; // remove suffix + if (strcat_s(imagePath, strLen, suffixName) != EOK) { // The format is xxx.bin + UIFree(reinterpret_cast(imagePath)); + imagePath = nullptr; + return false; + } + } } else { if (memcpy_s(imagePath, strLen, src, strLen) != EOK) { UIFree(reinterpret_cast(imagePath)); -- GitLab