-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
76 lines (68 loc) · 2.18 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2022 - 2023 opqr - caozhanhao
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "opqr/opqr.hpp"
#include <iostream>
using namespace opqr;
int main()
{
/*
* Add Data
*/
//1 constructor
QR qr1("https://github.com/caozhanhao/opqr");
QR qr2(std::vector<int>{0, 1, 2, 3});//or other containers, e.g. std::list
//2 add_data()
QR qr3;
QR qr4;
qr3.add_data({4, 5, 6, 7});// initializer_list
qr4.add_data(789);// integral value
/*
* Specify
*/
//1 constructor
QR qr5(20, ECLevel::Q, Mode::ALNUM, 0);
qr5.add_data("OPQR"); // string
//2 setter
QR qr6("12345");
qr6.set_version(10);
qr6.set_level(ECLevel::L);
qr6.set_mode(Mode::NUM);
qr6.set_mask(6);
/*
* Quiet Zone
*/
qr6.disable_quiet_zone();
/*
* Output
*/
// func output pic
// - paint(fmt, path/ostream, enlarge) -> (QR dimension * enlarge) * (QR dimension * enlarge)
// - paint(fmt, path/ostream, width, height) -> width * height
// 1 PNG
qr1.generate().paint(pic::Format::PNG, "examples/example1.png", 10);
std::ofstream fs("examples/example2.png", std::ios::binary | std::ios::out);
qr2.generate().paint(pic::Format::PNG, fs, 100);
fs.close();
// 2 JPG
auto qr = qr3.generate();
qr.paint(pic::Format::JPG, "examples/example3.jpg", 512, 512);
// 3 TGA
qr4.generate().paint(pic::Format::TGA, "examples/example4.tga", 5);
// 4 BMP
qr5.generate().paint(pic::Format::BMP, "examples/example5.bmp", 10);
qr6.generate().paint(pic::Format::BMP, "examples/example6.bmp", 1024, 1024);
// 5 ANSI
qr.paint(pic::Format::ANSI256, std::cout, 2);
return 0;
}