1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_IMAGE_UTIL_H 16 #define BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_IMAGE_UTIL_H 17 18 #include <memory> 19 #include <string> 20 #include "pixel_map.h" 21 22 namespace OHOS { 23 namespace Notification { 24 class AnsImageUtil { 25 public: 26 static const std::string IMAGE_FORMAT_PNG; 27 static const uint8_t IMAGE_QUALITY; 28 static const uint8_t SHIFT_FOUR; 29 static const uint8_t NUM_TEN; 30 static const size_t TWO_TIMES; 31 static const uint32_t DEFAULT_SIZE; 32 33 /** 34 * @brief Packs an image to a string. 35 * 36 * @param pixelMap Indicates the image to be packaged. 37 * @param format Indicates the format of the image. 38 * @return Returns a string. 39 */ 40 static std::string PackImage( 41 const std::shared_ptr<Media::PixelMap> &pixelMap, const std::string &format = IMAGE_FORMAT_PNG); 42 43 /** 44 * @brief Unpacks the string to an image. 45 * 46 * @param pixelMapStr Indicates the string of image. 47 * @return Returns an image object. 48 */ 49 static std::shared_ptr<Media::PixelMap> UnPackImage(const std::string &pixelMapStr, 50 const std::string &format = IMAGE_FORMAT_PNG); 51 52 /** 53 * @brief Packs an image to a file. 54 * 55 * @param pixelMap Indicates the image to be packaged. 56 * @param outFilePath Indicates the path of the output file. 57 * @param format Indicates the format of the image. 58 * @return Returns true if succeed; returns false otherwise. 59 */ 60 static bool PackImage2File( 61 const std::shared_ptr<Media::PixelMap> &pixelMap, 62 const std::string &outFilePath, 63 const std::string &format = IMAGE_FORMAT_PNG); 64 65 /** 66 * @brief Creates an image from a file. 67 * 68 * @param inFilePath Indicates the path of the input file. 69 * @param format Indicates the format of the image. 70 * @return Returns an image object. 71 */ 72 static std::shared_ptr<Media::PixelMap> CreatePixelMap( 73 const std::string &inFilePath, const std::string &format = IMAGE_FORMAT_PNG); 74 75 /** 76 * @brief Converts a binary string to a hexadecimal string. 77 * 78 * @param strBin Indicates the input binary string. 79 * @return Returns a hexadecimal string. 80 */ 81 static std::string BinToHex(const std::string &strBin); 82 83 /** 84 * @brief Converts a hexadecimal string to a binary string. 85 * 86 * @param strHex Indicates the input hexadecimal string. 87 * @return Returns a binary string. 88 */ 89 static std::string HexToBin(const std::string &strHex); 90 }; 91 } // namespace Notification 92 } // namespace OHOS 93 94 #endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_IMAGE_UTIL_H 95