二维码生成库的使用注意事项 libqrencode

cmake 修改

option(WITH_TOOLS "Build utility tools" YES )
option(WITH_TESTS "Build tests" NO )
option(WITHOUT_PNG "Disable PNG support" YES) #1.屏蔽PNG
option(GPROF "Generate extra code to write profile information" OFF)
option(COVERAGE "Generate extra code to write coverage information" OFF)
option(ASAN "Use AddressSanitizer" OFF)
option(BUILD_SHARED_LIBS "Enable build of shared libraries" YES)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") #2.动态库

qrencode 的数据结构 QRcode->data的最后一个bit表示的才是数据,不能直接使用if(QRcode->data)

/**
* QRcode class.
* Symbol data is represented as an array contains width*width uchars.
* Each uchar represents a module (dot). If the less significant bit of
* the uchar is 1, the corresponding module is black. The other bits are
* meaningless for usual applications, but here its specification is described.
*
* @verbatim
MSB 76543210 LSB
|||||||`- 1=black/0=white
||||||`-- 1=ecc/0=data code area
|||||`--- format information
||||`---- version information
|||`----- timing pattern
||`------ alignment pattern
|`------- finder pattern and separator
`-------- non-data modules (format, timing, etc.)
@endverbatim
*/
typedef struct {
int version; ///< version of the symbol
int width; ///< width of the symbol
unsigned char *data; ///< symbol data
} QRcode;

具体代码见gitee https://gitee.com/layty/libqrencode/blob/master/demo1.c 查看git log

原文地址:https://www.cnblogs.com/zongzi10010/p/13788688.html