From de1fb75c429eb4e996073939ae5b6dd464005970 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Tue, 10 Jan 2023 14:24:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=88=9B=E5=BB=BA=E5=A4=9A?= =?UTF-8?q?=E9=A1=B5tiff=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hgscannersdk/HG_SCANNER_API.cpp | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/sdk/oldwebscan/hgscannersdk/HG_SCANNER_API.cpp b/sdk/oldwebscan/hgscannersdk/HG_SCANNER_API.cpp index 728c3220..3c1afee0 100644 --- a/sdk/oldwebscan/hgscannersdk/HG_SCANNER_API.cpp +++ b/sdk/oldwebscan/hgscannersdk/HG_SCANNER_API.cpp @@ -914,32 +914,42 @@ void HG_SET_IMG_COMPRESSION(unsigned int compressiondata) }*/ DLL_HG_SCHANNER_API int HG_Create_MultiTiff(char** srcFiles, int srcnum, char* dstFile) { - /*int ret = 0; + int ret = 0; if (dstFile == nullptr || srcFiles == nullptr) return ret; std::string dstfilepath(dstFile); - LOG("dstFile = %s \n", dstfilepath.c_str()); - TIFF* tif_file = TIFFOpen(dstfilepath.c_str(), "w"); - if (!tif_file) - return ret; - + printf("dstFile = %s \n", dstfilepath.c_str()); int pageIndex = 0;//init page number + HGImgFmtLoadInfo info; + HGImage hgimg = NULL; + HGTiffWriter tifwriter; + HGImgFmt_OpenTiffWriter(dstfilepath.c_str(), &tifwriter); + HGTiffSaveInfo saveinfo; + saveinfo.compression = HGIMGFMT_TIFFCOMP_JPEG; + saveinfo.jpegQuality = 90; + saveinfo.resolutionUnit = HGIMGFMT_TIFFRESUNIT_INCH; + HGResult hgret; for (int i = 0; i < srcnum; i++)//convert imgs to tiff loop { + printf("filepath = %s \n", srcFiles[i]); std::string filepath(srcFiles[i]); if (filepath.length() > 4) { - cv::Mat img = cv::imread(srcFiles[i], cv::ImreadModes::IMREAD_ANYCOLOR); - if (!img.empty()) + hgret = HGImgFmt_LoadImage(srcFiles[i], 0, &info, 0, 0, &hgimg); + if (hgret == HGBASE_ERR_OK) { - if (img.channels() == 3) - cv::cvtColor(img, img, CV_BGR2RGB); - - img2tiff(tif_file, pageIndex, img, 80); - pageIndex++; + saveinfo.xResolution = info.xDpi; + saveinfo.yResolution = info.yDpi; + hgret = HGImgFmt_SaveImageToTiffWriter(tifwriter, hgimg, &saveinfo); + printf("\nHGImgFmt_SaveImageToTiffWriter %d", hgret); + } + else + { + printf("\nHGImgFmt_LoadImage error %d", hgret); } } } - TIFFClose(tif_file);*/ - return -1; + hgret = HGImgFmt_CloseTiffWriter(tifwriter); + printf("\nHGImgFmt_CloseTiffWriter %d", hgret); + return 1; } \ No newline at end of file