22#include < Windows.h>
33#include < tchar.h>
44#pragma comment(lib,"Ws2_32")
5+ #pragma comment(lib,"jsoncpp")
56#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
67#pragma comment(lib,"XEngine_NetHelp/NetHelp_APIClient")
8+ #pragma comment(lib,"XEngine_SystemSdk/XEngine_SystemApi")
79#endif
810#include < stdio.h>
911#include < stdlib.h>
1012#include < string.h>
1113#include < inttypes.h>
14+ #include < json/json.h>
1215#include < XEngine_Include/XEngine_CommHdr.h>
1316#include < XEngine_Include/XEngine_Types.h>
1417#include < XEngine_Include/XEngine_ProtocolHdr.h>
1518#include < XEngine_Include/XEngine_BaseLib/BaseLib_Define.h>
1619#include < XEngine_Include/XEngine_BaseLib/BaseLib_Error.h>
1720#include < XEngine_Include/XEngine_NetHelp/APIClient_Define.h>
1821#include < XEngine_Include/XEngine_NetHelp/APIClient_Error.h>
22+ #include < XEngine_Include/XEngine_SystemSdk/ProcFile_Define.h>
23+ #include < XEngine_Include/XEngine_SystemSdk/SystemApi_Define.h>
24+ #include < XEngine_Include/XEngine_SystemSdk/SystemApi_Error.h>
1925
2026// 需要优先配置XEngine
2127// WINDOWS支持VS2022 x64 debug 编译调试
2228// linux::g++ -std=c++17 -Wall -g APPClient_ImageExample.cpp -o APPClient_ImageExample.exe -L /usr/local/lib/XEngine_Release/XEngine_BaseLib -L /usr/local/lib/XEngine_Release/XEngine_NetHelp -lXEngine_BaseLib -lNetHelp_APIClient
2329// macos::g++ -std=c++17 -Wall -g APPClient_ImageExample.cpp -o APPClient_ImageExample.exe -lXEngine_BaseLib -lNetHelp_APIClient
2430
2531
26- int test_query ( )
32+ bool APPClient_ImageExample_GetAttr (LPCXSTR lpszMsgBuffer, int nMsgLen, int * pInt_Width, int * pInt_Height )
2733{
2834 int nCode = 0 ;
29- XCHAR* ptszFileBuffer = (XCHAR*)malloc (XENGINE_MEMORY_SIZE_MAX);
30- if (NULL == ptszFileBuffer)
31- {
32- return -1 ;
33- }
34- memset (ptszFileBuffer, ' \0 ' , XENGINE_MEMORY_SIZE_MAX);
35-
3635 LPCXSTR lpszAPIUrl = _X (" http://127.0.0.1:5501/api?function=image¶ms1=0" );
3736
38- FILE* pSt_File = _xtfopen (_X (" D:\\ XEngine_APIService\\ XEngine_APPClient\\ x64\\ Debug\\ 1.png" ), " rb" );
39- int nRet = fread (ptszFileBuffer, 1 , XENGINE_MEMORY_SIZE_MAX, pSt_File);
40-
4137 XCHAR* ptszMsgBuffer = NULL ;
42- if (!APIClient_Http_Request (_X (" POST" ), lpszAPIUrl, ptszFileBuffer , &nCode, &ptszMsgBuffer, &nRet ))
38+ if (!APIClient_Http_Request (_X (" POST" ), lpszAPIUrl, lpszMsgBuffer , &nCode, &ptszMsgBuffer, &nMsgLen ))
4339 {
4440 printf (" 发送投递失败!\n " );
4541 return 0 ;
4642 }
47- printf (" 接受到数据,大小:%d,内容:%s\n " , nRet, ptszMsgBuffer);
43+ Json::Value st_JsonRoot;
44+ JSONCPP_STRING st_JsonError;
45+ Json::CharReaderBuilder st_JsonBuilder;
46+ // 开始解析配置文件
47+ std::unique_ptr<Json::CharReader> const pSt_JsonReader (st_JsonBuilder.newCharReader ());
48+ if (!pSt_JsonReader->parse (ptszMsgBuffer, ptszMsgBuffer + nMsgLen, &st_JsonRoot, &st_JsonError))
49+ {
50+ printf (" json parse failed\n " );
51+ return false ;
52+ }
4853 BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
49- free (ptszFileBuffer);
54+
55+ Json::Value st_JsonBase = st_JsonRoot[" st_BaseInfo" ];
56+ *pInt_Width = st_JsonBase[" nWidth" ].asInt ();
57+ *pInt_Height = st_JsonBase[" nHeigth" ].asInt ();
58+ return 0 ;
59+ }
60+ int test_imgzoom ()
61+ {
62+ LPCXSTR lpszFileDir = _X (" D:\\ Image\\ *.png" );
63+
64+ int nListCount = 0 ;
65+ XCHAR** pptszListFile;
66+
67+ SystemApi_File_EnumFile (lpszFileDir, &pptszListFile, &nListCount);
68+ for (int i = 0 ; i < nListCount; i++)
69+ {
70+ int nCode = 0 ;
71+ int nWidth = 0 ;
72+ int nHeight = 0 ;
73+ XCHAR* ptszFileBuffer = (XCHAR*)malloc (XENGINE_MEMORY_SIZE_MAX);
74+ if (NULL == ptszFileBuffer)
75+ {
76+ return -1 ;
77+ }
78+ memset (ptszFileBuffer, ' \0 ' , XENGINE_MEMORY_SIZE_MAX);
79+
80+ FILE* pSt_File = _xtfopen (pptszListFile[i], _X (" rb" ));
81+ int nRet = (int )fread (ptszFileBuffer, 1 , XENGINE_MEMORY_SIZE_MAX, pSt_File);
82+ fclose (pSt_File);
83+ APPClient_ImageExample_GetAttr (ptszFileBuffer, nRet, &nWidth, &nHeight);
84+
85+ XCHAR tszAPIUrl[MAX_PATH];
86+ memset (tszAPIUrl, ' \0 ' , sizeof (tszAPIUrl));
87+
88+ _xstprintf (tszAPIUrl, _X (" http://127.0.0.1:5501/api?function=image&type=1&ext=png&width=%d&height=%d" ), nWidth / 2 , nHeight / 2 );
89+
90+ XCHAR* ptszMsgBuffer = NULL ;
91+ if (!APIClient_Http_Request (_X (" POST" ), tszAPIUrl, ptszFileBuffer, &nCode, &ptszMsgBuffer, &nRet))
92+ {
93+ printf (" 发送投递失败!\n " );
94+ return 0 ;
95+ }
96+ free (ptszFileBuffer);
97+
98+ pSt_File = _xtfopen (pptszListFile[i], _X (" wb" ));
99+ fwrite (ptszMsgBuffer, 1 , nRet, pSt_File);
100+ fclose (pSt_File);
101+
102+ BaseLib_OperatorMemory_FreeCStyle ((XPPMEM)&ptszMsgBuffer);
103+ }
104+
105+
50106 return 0 ;
51107}
52108
@@ -56,7 +112,8 @@ int main()
56112 WSADATA st_WSAData;
57113 WSAStartup (MAKEWORD (2 , 2 ), &st_WSAData);
58114#endif
59- test_query ();
115+
116+ test_imgzoom ();
60117
61118#ifdef _MSC_BUILD
62119 WSACleanup ();
0 commit comments