How to save a QRCode struct in libqrencode as an image c++

I am using libqrencode to create a QR image in c++ (VS 2013) this is my basic program

QRcode *QR;
string mode=Data_Analysis(input);
if (mode == "numeric"){
int version = Choose_Version(error, Numeric, input.length());
QR = QRcode_encodeString(input_char, version, error_level, QR_MODE_NUM, 0);
}
if (mode == "alphanumeric"){
int version = Choose_Version(error, AlphaNumeric, input.length());
QR = QRcode_encodeString(input_char, version, error_level, QR_MODE_AN, 0);
}
if (mode == "byte"){
int version = Choose_Version(error, Byte, input.length());
QR = QRcode_encodeString(input_char, version, error_level, QR_MODE_8, 0);
}
The problem now is, I do not know how to write it as an image file. .jpg or .bmp or .png would great .I read the documentation of libqrencode and found no help into saving it as a file. I tried using the library 'EasyBMP' but i couldn't figure out how convert the data from the QRCode class. please help me. If there is an easier way to this, then i'm all ears.
Last edited on
A simple solution if linking an image library is overkill, is to write the bitmap as an 8- or 32-bit RAW image containing only the pixel values and nothing else, and open it using an application that supports the format. I generally use IrfanView, which lets me input the dimensions, bit depth, channel ordering, etc.

1
2
3
4
5
std::ofstream file("output.raw", std::ios::binary);
int n = QR->width;
n *= n;
for (int i = 0; i < n; i++)
    file.put((char)((QR->data[i] & 1) ? 0x00 : 0xFF));
Topic archived. No new replies allowed.