From 4ebe630bcb9aae4f0d4d0da6de8f96ae1c4ebd1c Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 26 Feb 2025 18:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=99=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8E=E7=AB=8B=E5=8D=B3=E9=87=8D=E5=90=AF=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=A9=BA=E6=96=87=E4=BB=B6=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) 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