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);