From e9a6938e7ea63cf54aa8628f44eff8eb9d57b8af Mon Sep 17 00:00:00 2001 From: zhengzhuolan Date: Tue, 6 May 2025 10:25:27 +0800 Subject: [PATCH] picture scale Signed-off-by: zhengzhuolan --- frameworks/js/napi/include/common.h | 2 ++ frameworks/js/napi/src/common_convert_request.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/frameworks/js/napi/include/common.h b/frameworks/js/napi/include/common.h index cb29b57f0..f00dcc256 100644 --- a/frameworks/js/napi/include/common.h +++ b/frameworks/js/napi/include/common.h @@ -42,6 +42,7 @@ constexpr uint8_t PARAM1 = 1; constexpr uint8_t PARAM2 = 2; constexpr uint8_t PARAM3 = 3; constexpr uint8_t PARAM4 = 4; +constexpr float MAX_PIXEL_SIZE = 128.0f; enum class SemanticActionButton { NONE_ACTION_BUTTON, @@ -1853,6 +1854,7 @@ public: static napi_value SetObjectUint32Property(const napi_env &env, napi_value& object, const std::string& key, uint32_t value); static std::string GetAppInstanceKey(); + static void PictureScale(std::shared_ptr pixelMap); private: static const int32_t ARGS_ONE = 1; static const int32_t ARGS_TWO = 2; diff --git a/frameworks/js/napi/src/common_convert_request.cpp b/frameworks/js/napi/src/common_convert_request.cpp index bf3bbfdba..0ad27f935 100644 --- a/frameworks/js/napi/src/common_convert_request.cpp +++ b/frameworks/js/napi/src/common_convert_request.cpp @@ -788,6 +788,7 @@ napi_value Common::GetNotificationSmallIcon(const napi_env &env, const napi_valu ANS_LOGE("Invalid object pixelMap"); return nullptr; } + Common::PictureScale(pixelMap); request.SetLittleIcon(pixelMap); } @@ -818,6 +819,7 @@ napi_value Common::GetNotificationLargeIcon(const napi_env &env, const napi_valu ANS_LOGE("Invalid object pixelMap"); return nullptr; } + Common::PictureScale(pixelMap); request.SetBigIcon(pixelMap); } @@ -849,6 +851,7 @@ napi_value Common::GetNotificationOverlayIcon( ANS_LOGE("Invalid object pixelMap"); return nullptr; } + Common::PictureScale(pixelMap); request.SetOverlayIcon(pixelMap); } @@ -2046,5 +2049,17 @@ napi_value Common::GetNotificationControlFlags( return NapiGetNull(env); } + +void Common::PictureScale(std::shared_ptr pixelMap) +{ + int32_t size = pixelMap->GetByteCount(); + if (size <= MAX_ICON_SIZE) { + return; + } + int32_t width = pixelMap->GetWidth(); + int32_t height = pixelMap->GetHeight(); + float Axis = MAX_PIXEL_SIZE / std::max(width, height); + pixelMap->scale(Axis, Axis, Media::AntiAliasingOption::HIGH); +} } } -- Gitee