Как cpp-ZXing генерирует QR-код с широкими символами?C++

Программы на C++. Форум разработчиков
Anonymous
Как cpp-ZXing генерирует QR-код с широкими символами?

Сообщение Anonymous »

Код: Выделить всё

#include "ReadBarcode.h"
#include 
#include 
#include 

#include "BitMatrix.h"
#include "BitMatrixIO.h"
#include "CharacterSet.h"
#include "MultiFormatWriter.h"

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include 

#define STB_IMAGE_IMPLEMENTATION
#include 

using namespace ZXing;

int main(int argc, char * argv[]){

int sizeHint = 100;
auto format = BarcodeFormatFromString("QRCode");
auto writer = MultiFormatWriter(format).setMargin(10);

//writer.setEncoding(CharacterSet::UTF8);

// this will work with char*
BitMatrix matrix = writer.encode("ddd", sizeHint, sizeHint);

/* with Chinese charaters, the QR Code will be generated, but it
cannot be recognized by online public QR scanner.
I've tried serveral ways. */

// attempt 1. directly replace the paramter with `const w_char*`
// BitMatrix matrix = writer.encode(L"你好", sizeHint, sizeHint);

// attempt 2. build a std::wstring
// std::wtring word = L"你好";
// BitMatrix matrix = writer.encode(word, sizeHint, sizeHint);

auto bitmap = ToMatrix(matrix);
int success = stbi_write_png("C:\\Users\\chenz\\Desktop\\2.png", bitmap.width(), bitmap.height(), 1, bitmap.data(), 0);

if (!success) {
std::cerr 

Подробнее здесь: [url]https://stackoverflow.com/questions/79233039/how-cpp-zxing-generate-qr-code-with-wide-characters[/url]

Вернуться в «C++»