diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 005b5af1..3e0b8c19 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -48,6 +48,30 @@ extern bool GetJniEnv(JavaVM *vm, JNIEnv **env, bool& didAttachThread); // are normalized to eight bits. static const int kMaxChannelValue = 262143; +bool WriteMatToFile(const std::string& fileName, const cv::InputArray& img, const std::vector& params = std::vector()) +{ + std::vector imgContents; + size_t imgFileSize = 0; + std::string ext; + auto pos = fileName.rfind('.'); + if (pos != std::string::npos) + { + ext = fileName.substr(pos); + } + else + { + ext = ".jpg"; + } + + bool res = cv::imencode(ext, img, imgContents, params); + if (res) + { + res = writeFile(fileName.c_str(), &imgContents[0], imgContents.size()); + } + + return res; +} + class ByteArraysPointer { public: @@ -2705,7 +2729,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat mat) if (!std::filesystem::exists(std::filesystem::path(fullPath))) { - bool res = cv::imwrite(fullPath.c_str(), mat, params); + bool res = WriteMatToFile(fullPath.c_str(), mat, params); if (!res) { XYLOG(XYLOG_SEVERITY_ERROR, "Failed to write photo: %s", fullPath.c_str()); @@ -2956,7 +2980,7 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector