Linux使用libqrcode生成二维码图片

之前在做跟华为合作的项目,需要根据字串来生成特定的二维码,特在此记录,以便查看。

二维码图样有很多种,根据项目要求,我选择了使用libqrcode库来实现,这是个开源库,使用十分方便,首先下载libqrcode源码,根据平台选择编译条件并编译成动态库so。在自己编写程序包含相应的头文件,编译链接动态库即可。

以下是我部分code,仅供参考。

qrcode.h

#ifndef _QRCODE_H_
#define _QRCODE_H_

#ifdef __cplusplus
extern "C"{
#endif

#include "qrencode.h"

enum imageType {
	PNG_TYPE,
	PNG32_TYPE,
	EPS_TYPE,
	SVG_TYPE,
	XPM_TYPE,
	ANSI_TYPE,
	ANSI256_TYPE,
	ASCII_TYPE,
	ASCIIi_TYPE,
	UTF8_TYPE,
	ANSIUTF8_TYPE,
	UTF8i_TYPE,
	ANSIUTF8i_TYPE
};

int makeQrcode(const char *SourceSring, const char *path);



#ifdef __cplusplus
}
#endif

#endif

qrcode.cpp

#include <string.h>
#include <errno.h>
//#include <conio.h>
#include <ctype.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <wchar.h>
#include <png.h>

#include "qrcode.h"


#pragma pack(push, 2)
#pragma pack(pop)

#define INCHES_PER_METER (100.0/2.54)

static int margin = 1;
static int size = 8;  //qrcode size
static unsigned char fg_color[4] = {0, 0, 0, 255};
static unsigned char bg_color[4] = {201, 201, 201, 255};
static int dpi = 72;

static void fillRow(unsigned char *row, int num, const unsigne
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值