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_JPEG; 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 32 /** 33 * @brief Packs an image to a string. 34 * 35 * @param pixelMap Indicates the image to be packaged. 36 * @param format Indicates the format of the image. 37 * @return Returns a string. 38 */ 39 static std::string PackImage( 40 const std::shared_ptr<Media::PixelMap> &pixelMap, const std::string &format = IMAGE_FORMAT_JPEG); 41 42 /** 43 * @brief Unpacks the string to an image. 44 * 45 * @param pixelMapStr Indicates the string of image. 46 * @return Returns an image object. 47 */ 48 static std::shared_ptr<Media::PixelMap> UnPackImage(const std::string &pixelMapStr); 49 50 /** 51 * @brief Packs an image to a file. 52 * 53 * @param pixelMap Indicates the image to be packaged. 54 * @param outFilePath Indicates the path of the output file. 55 * @param format Indicates the format of the image. 56 * @return Returns true if succeed; returns false otherwise. 57 */ 58 static bool PackImage2File( 59 const std::shared_ptr<Media::PixelMap> &pixelMap, 60 const std::string &outFilePath, 61 const std::string &format = IMAGE_FORMAT_JPEG); 62 63 /** 64 * @brief Creates an image from a file. 65 * 66 * @param inFilePath Indicates the path of the input file. 67 * @param format Indicates the format of the image. 68 * @return Returns an image object. 69 */ 70 static std::shared_ptr<Media::PixelMap> CreatePixelMap( 71 const std::string &inFilePath, const std::string &format = IMAGE_FORMAT_JPEG); 72 73 /** 74 * @brief Converts a binary string to a hexadecimal string. 75 * 76 * @param strBin Indicates the input binary string. 77 * @return Returns a hexadecimal string. 78 */ 79 static std::string BinToHex(const std::string &strBin); 80 81 /** 82 * @brief Converts a hexadecimal string to a binary string. 83 * 84 * @param strHex Indicates the input hexadecimal string. 85 * @return Returns a binary string. 86 */ 87 static std::string HexToBin(const std::string &strHex); 88 }; 89 } // namespace Notification 90 } // namespace OHOS 91 92 #endif // BASE_NOTIFICATION_ANS_STANDARD_FRAMEWORKS_ANS_CORE_INCLUDE_ANS_IMAGE_UTIL_H 93