From a205ee22f999fa2257013c920dfc96897ce01f97 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 25 Feb 2025 11:38:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=85=A7=E7=89=87=E5=86=99?= =?UTF-8?q?=E5=85=A5=E6=96=87=E4=BB=B6=E7=9A=84=E5=AE=9E=E7=8E=B0=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 40 +++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index f41e104b..495fe5aa 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -3645,16 +3645,44 @@ bool CPhoneDevice::PostProcessPhoto(const PHOTO_INFO& photoInfo, const vector 0) + std::vector imgContents; + size_t imgFileSize = 0; + bool res = cv::imencode(".jpg", mat, imgContents, params); + if (res) { - res = (rename(tmpPath.c_str(), fullPath.c_str()) == 0); + int errcode = 0; + res = writeFile(tmpPath.c_str(), &imgContents[0], imgContents.size(), errcode); + if (res) + { + if (existsFile(tmpPath)) + { + imgFileSize = getFileSize(tmpPath); + if (imgFileSize == 0) + { + XYLOG(XYLOG_SEVERITY_ERROR, "Empty File Written: %s errno=%d", tmpPath.c_str() + m_appPath.size(), errcode); + remove(tmpPath.c_str()); + res = false; + } + } + } + else + { + XYLOG(XYLOG_SEVERITY_ERROR, "Failed to Write File: %s errno=%d", tmpPath.c_str() + m_appPath.size(), errcode); + if (existsFile(tmpPath)) + { + remove(tmpPath.c_str()); + } + } } else { - remove(tmpPath.c_str()); - res = false; + int errcode = errno; + XYLOG(XYLOG_SEVERITY_ERROR, "Failed to Encode Image CH=%u PR=%u IMGID=%u, errno=%d", (uint32_t)photoInfo.channel, (uint32_t)photoInfo.preset, (uint32_t)photoInfo.photoId, errcode); + } + // bool res = cv::imwrite(tmpPath.c_str(), mat, params); + if (res/* && imgFileSize > 0*/) + { + res = (rename(tmpPath.c_str(), fullPath.c_str()) == 0); } #else bool res = cv::imwrite(fullPath.c_str(), mat, params);