扫描、图像合成、纠偏等功能,可以设置参数来决定是否返回base64
This commit is contained in:
parent
f115bdceda
commit
e749a6691b
Binary file not shown.
|
@ -163,6 +163,7 @@ namespace ver_2
|
|||
m_initDeviceHaveIden = false;
|
||||
m_startScanIden.clear();
|
||||
m_startScanHaveIden = false;
|
||||
m_startScanIsGetBase64 = false;
|
||||
|
||||
GetManager()->SetSaneEvent(SaneEvent2, this);
|
||||
GetManager()->SetSaneImageCallback(SaneImageCallback2, this);
|
||||
|
@ -721,14 +722,35 @@ namespace ver_2
|
|||
{
|
||||
WSUser* p = (WSUser*)param;
|
||||
|
||||
char resp[1024];
|
||||
std::string base64;
|
||||
if (p->m_startScanIsGetBase64)
|
||||
{
|
||||
std::string errInfo;
|
||||
p->GetManager()->LoadLocalImage(path, base64, errInfo);
|
||||
}
|
||||
|
||||
char* resp = new char[1024 + base64.size()];
|
||||
if (p->m_startScanHaveIden)
|
||||
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\", \"image_path\":\"%s\"}",
|
||||
"scan_image", p->m_startScanIden.c_str(), StdStringToUtf8(strToJson(path)).c_str());
|
||||
{
|
||||
if (p->m_startScanIsGetBase64)
|
||||
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\", \"image_path\":\"%s\", \"image_base64\":\"%s\"}",
|
||||
"scan_image", p->m_startScanIden.c_str(), StdStringToUtf8(strToJson(path)).c_str(), base64.c_str());
|
||||
else
|
||||
sprintf(resp, "{\"func\":\"%s\", \"iden\":\"%s\", \"image_path\":\"%s\"}",
|
||||
"scan_image", p->m_startScanIden.c_str(), StdStringToUtf8(strToJson(path)).c_str());
|
||||
}
|
||||
else
|
||||
sprintf(resp, "{\"func\":\"%s\", \"image_path\":\"%s\"}",
|
||||
"scan_image", StdStringToUtf8(strToJson(path)).c_str());
|
||||
{
|
||||
if (p->m_startScanIsGetBase64)
|
||||
sprintf(resp, "{\"func\":\"%s\", \"image_path\":\"%s\", \"image_base64\":\"%s\"}",
|
||||
"scan_image", StdStringToUtf8(strToJson(path)).c_str(), base64.c_str());
|
||||
else
|
||||
sprintf(resp, "{\"func\":\"%s\", \"image_path\":\"%s\"}",
|
||||
"scan_image", StdStringToUtf8(strToJson(path)).c_str());
|
||||
}
|
||||
|
||||
p->PostEventMsg((const HGByte*)resp, (HGUInt)strlen(resp));
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
std::string WSUser::strToJson(const std::string str)
|
||||
|
@ -745,9 +767,6 @@ namespace ver_2
|
|||
case '\\':
|
||||
ret.append("\\\\");
|
||||
break;
|
||||
case '/':
|
||||
ret.append("\\/");
|
||||
break;
|
||||
case '\b':
|
||||
ret.append("\\b");
|
||||
break;
|
||||
|
@ -1241,6 +1260,14 @@ namespace ver_2
|
|||
std::string errInfo;
|
||||
int ret = GetManager()->MergeLocalImage(imagePathList, mode, align, interval, outImagePath, errInfo);
|
||||
|
||||
std::string outImageBase64;
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
if (0 == ret && getBase64)
|
||||
{
|
||||
std::string errInfo2;
|
||||
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
||||
}
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
|
@ -1256,10 +1283,18 @@ namespace ver_2
|
|||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
if (getBase64)
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\", ";
|
||||
fmt += "\"image_base64\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
}
|
||||
}
|
||||
|
||||
char resp[1024] = { 0 };
|
||||
char* resp = new char[1024 + outImageBase64.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
|
@ -1270,12 +1305,25 @@ namespace ver_2
|
|||
else
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "merge_local_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "merge_local_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "merge_local_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "merge_local_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "merge_local_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "merge_local_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::LocalMakeMultiImage(cJSON* json)
|
||||
|
@ -1301,6 +1349,14 @@ namespace ver_2
|
|||
std::string errInfo;
|
||||
int ret = GetManager()->LocalMakeMultiImage(imagePathList, format, tiffCompression, tiffJpegQuality, outImagePath, errInfo);
|
||||
|
||||
std::string outImageBase64;
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
if (0 == ret && getBase64)
|
||||
{
|
||||
std::string errInfo2;
|
||||
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
||||
}
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
|
@ -1316,10 +1372,18 @@ namespace ver_2
|
|||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
if (getBase64)
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\", ";
|
||||
fmt += "\"image_base64\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
}
|
||||
}
|
||||
|
||||
char resp[1024] = { 0 };
|
||||
char* resp = new char[1024 + outImageBase64.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
|
@ -1330,12 +1394,25 @@ namespace ver_2
|
|||
else
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "local_make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "local_make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "local_make_multi_image", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "local_make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "local_make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "local_make_multi_image", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::SplitLocalImage(cJSON* json)
|
||||
|
@ -1356,6 +1433,19 @@ namespace ver_2
|
|||
std::string errInfo;
|
||||
int ret = GetManager()->SplitLocalImage(imagePath, mode, location, outImagePathList, errInfo);
|
||||
|
||||
std::vector<std::string> outImageBase64List;
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
if (0 == ret && getBase64)
|
||||
{
|
||||
for (int i = 0; i < (int)outImagePathList.size(); ++i)
|
||||
{
|
||||
std::string outImageBase64;
|
||||
std::string errInfo2;
|
||||
GetManager()->LoadLocalImage(outImagePathList[i], outImageBase64, errInfo2);
|
||||
outImageBase64List.push_back(outImageBase64);
|
||||
}
|
||||
}
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
|
@ -1371,7 +1461,15 @@ namespace ver_2
|
|||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"image_path_list\":%s}";
|
||||
if (getBase64)
|
||||
{
|
||||
fmt += "\"image_path_list\":%s, ";
|
||||
fmt += "\"image_base64_list\":%s}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"image_path_list\":%s}";
|
||||
}
|
||||
}
|
||||
|
||||
std::string pathList = "[";
|
||||
|
@ -1387,7 +1485,20 @@ namespace ver_2
|
|||
}
|
||||
pathList += "]";
|
||||
|
||||
char resp[1024] = { 0 };
|
||||
std::string base64List = "[";
|
||||
for (int i = 0; i < (int)outImageBase64List.size(); ++i)
|
||||
{
|
||||
base64List += "\"";
|
||||
base64List += outImageBase64List[i];
|
||||
base64List += "\"";
|
||||
if (i != (int)outImageBase64List.size() - 1)
|
||||
{
|
||||
base64List += ", ";
|
||||
}
|
||||
}
|
||||
base64List += "]";
|
||||
|
||||
char* resp = new char[1024 + base64List.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
|
@ -1398,12 +1509,25 @@ namespace ver_2
|
|||
else
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, pathList.c_str());
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, pathList.c_str(),
|
||||
base64List.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", iden.c_str(), ret, pathList.c_str());
|
||||
}
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", ret, pathList.c_str());
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", ret, pathList.c_str(),
|
||||
base64List.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "split_local_image", ret, pathList.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::LocalMakeZipFile(cJSON* json)
|
||||
|
@ -1465,6 +1589,14 @@ namespace ver_2
|
|||
std::string errInfo;
|
||||
int ret = GetManager()->LocalImageDeskew(imagePath, outImagePath, errInfo);
|
||||
|
||||
std::string outImageBase64;
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
if (0 == ret && getBase64)
|
||||
{
|
||||
std::string errInfo2;
|
||||
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
||||
}
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
||||
|
@ -1480,10 +1612,18 @@ namespace ver_2
|
|||
else
|
||||
{
|
||||
fmt += "\"ret\":%d, ";
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
if (getBase64)
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\", ";
|
||||
fmt += "\"image_base64\":\"%s\"}";
|
||||
}
|
||||
else
|
||||
{
|
||||
fmt += "\"image_path\":\"%s\"}";
|
||||
}
|
||||
}
|
||||
|
||||
char resp[1024] = { 0 };
|
||||
char* resp = new char[1024 + outImageBase64.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
|
@ -1494,12 +1634,25 @@ namespace ver_2
|
|||
else
|
||||
{
|
||||
if (findIden)
|
||||
sprintf(resp, fmt.c_str(), "local_image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "local_image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "local_image_deskew", iden.c_str(), ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "local_image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
{
|
||||
if (getBase64)
|
||||
sprintf(resp, fmt.c_str(), "local_image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str(),
|
||||
outImageBase64.c_str());
|
||||
else
|
||||
sprintf(resp, fmt.c_str(), "local_image_deskew", ret, StdStringToUtf8(strToJson(outImagePath)).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::UploadLocalFile(cJSON* json)
|
||||
|
@ -2097,19 +2250,22 @@ namespace ver_2
|
|||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||
|
||||
if (!GetManager()->IsScanning())
|
||||
{
|
||||
m_startScanIden = iden;
|
||||
m_startScanHaveIden = findIden;
|
||||
m_startScanIsGetBase64 = getBase64;
|
||||
}
|
||||
|
||||
std::string errInfo;
|
||||
int ret = GetManager()->StartScan(errInfo);
|
||||
if (0 == ret)
|
||||
if (0 != ret)
|
||||
{
|
||||
m_startScanIden.clear();
|
||||
m_startScanHaveIden = false;
|
||||
m_startScanIsGetBase64 = false;
|
||||
}
|
||||
|
||||
std::string fmt;
|
||||
|
@ -2154,6 +2310,7 @@ namespace ver_2
|
|||
|
||||
m_startScanIden.clear();
|
||||
m_startScanHaveIden = false;
|
||||
m_startScanIsGetBase64 = false;
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
|
|
@ -69,5 +69,6 @@ namespace ver_2
|
|||
bool m_initDeviceHaveIden;
|
||||
std::string m_startScanIden;
|
||||
bool m_startScanHaveIden;
|
||||
bool m_startScanIsGetBase64;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -50,11 +50,8 @@
|
|||
}
|
||||
else if ("merge_local_image" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
|
||||
var req = {'func':'load_local_image', 'image_path':''};
|
||||
req.image_path = message['image_path'];
|
||||
socket.send(JSON.stringify(req));
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = message['image_base64'];
|
||||
}
|
||||
else if ("local_make_multi_image" == message['func'])
|
||||
{
|
||||
|
@ -62,7 +59,8 @@
|
|||
}
|
||||
else if ("split_local_image" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = message['image_base64_list'][0];
|
||||
}
|
||||
else if ("local_make_zip_file" == message['func'])
|
||||
{
|
||||
|
@ -70,7 +68,8 @@
|
|||
}
|
||||
else if ("local_image_deskew" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = message['image_base64'];
|
||||
}
|
||||
else if ("upload_local_file" == message['func'])
|
||||
{
|
||||
|
@ -139,22 +138,13 @@
|
|||
}
|
||||
else if ("scan_image" == message['func'])
|
||||
{
|
||||
var info = document.getElementById('info');
|
||||
info.value = msg.data;
|
||||
|
||||
var req = {'func':'load_local_image', 'image_path':''};
|
||||
req.image_path = message['image_path'];
|
||||
socket.send(JSON.stringify(req));
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = message['image_base64'];
|
||||
}
|
||||
else if ("stop_scan" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
}
|
||||
else if ("load_local_image" == message['func'])
|
||||
{
|
||||
var myCanvas = document.getElementById("myCanvas");
|
||||
myCanvas.src = message['image_base64'];
|
||||
}
|
||||
else if ("get_batch_id_list" == message['func'])
|
||||
{
|
||||
alert(msg.data);
|
||||
|
@ -223,7 +213,8 @@
|
|||
'image_path_list':['D:\\1.jpg','D:\\2.jpg'],
|
||||
'mode':'horz',
|
||||
'align':'center',
|
||||
'interval':20
|
||||
'interval':20,
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -234,7 +225,8 @@
|
|||
'image_path_list':['D:\\1.jpg','D:\\2.jpg'],
|
||||
'format':'tif',
|
||||
'tiff_compression':'jpeg',
|
||||
'tiff_jpeg_quality':60
|
||||
'tiff_jpeg_quality':60,
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -244,7 +236,8 @@
|
|||
'func':'split_local_image',
|
||||
'image_path':'D:\\1.jpg',
|
||||
'mode':'horz',
|
||||
'location':500
|
||||
'location':500,
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -260,7 +253,8 @@
|
|||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'local_image_deskew',
|
||||
'image_path':'D:\\1.jpg'
|
||||
'image_path':'D:\\1.jpg',
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -335,7 +329,8 @@
|
|||
function StartScan()
|
||||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'start_scan'
|
||||
'func':'start_scan',
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue