| 198 | } |
| 199 | |
| 200 | OH_ImageSourceNative* NativeCodec::CreateImageSource() const { |
| 201 | OH_ImageSourceNative* imageSource = nullptr; |
| 202 | if (imagePath.empty()) { |
| 203 | auto errorCode = OH_ImageSourceNative_CreateFromData(const_cast<uint8_t*>(imageBytes->bytes()), |
| 204 | imageBytes->size(), &imageSource); |
| 205 | if (errorCode != IMAGE_SUCCESS) { |
| 206 | LOGE("NativeCodec::CreateImageSource() Failed to CreateFromData"); |
| 207 | return nullptr; |
| 208 | } |
| 209 | } else { |
| 210 | auto errorCode = |
| 211 | OH_ImageSourceNative_CreateFromUri(const_cast<char*>(imagePath.c_str()), |
| 212 | static_cast<size_t>(imagePath.length()), &imageSource); |
| 213 | if (errorCode != IMAGE_SUCCESS) { |
| 214 | LOGE("NativeCodec::CreateImageSource() Failed to CreateFromUri: %s", imagePath.c_str()); |
| 215 | return nullptr; |
| 216 | } |
| 217 | } |
| 218 | return imageSource; |
| 219 | } |
| 220 | |
| 221 | } // namespace tgfx |