Skip to content

caozhanhao/opqr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

opqr

A C++ header-only QR encode Library.

Release

  • header only
  • easy to use

Setup

just #include "opqr/opqr.hpp".

Usage

Add Data

constructor
QR qr1("https://github.com/caozhanhao/opqr"); // string
QR qr2(std::vector{ 0,1,2,3 });//or other containers, e.g. std::list, std::initializer_list
add_data()
QR qr1;
qr1.add_data({ 4,5,6,7 });// initializer_list or some containers
QR qr2;
qr2.add_data(789);        // integral value

Specify

constructor
QR qr(20, ECLevel::Q, Mode::ALNUM, 0);
setter
QR qr("12345"); 
qr.set_version(10);
qr.set_level(ECLevel::L);
qr.set_mode(Mode::NUM);
qr.set_mask(6);

Quiet Zone

qr.disable_quiet_zone();

Output

Support Format
  • JPG
  • PNG
  • TGA
  • BMP
  • ANSI
paint(format, filename/ostream, enlarge)
  • the image size = dimension * enlarge x dimension * enlarge
paint(format, filename/ostream, width, height)
  • the image size = width x height
auto pic = qr.generate();
pic.paint(pic::Format::BMP, "example.bmp", 10);
std::ofstream fs("examples/example2.png", std::ios::binary | std::ios::out);
pic.paint(pic::Format::PNG, fs, 1024, 1024);
fs.close();

For more examples, see here

Note

  • There may be bugs in Kanji Mode

Dependency

  • stb (also header-only)
  • C++ 17

Reference

二维码生成原理