Vikash Posted October 31, 2023 Report Posted October 31, 2023 Hi, I have generated QR code like : QRcode *qr = QRcode_encodeString("Data", 0, QRecLevel::QR_ECLEVEL_M, QRencodeMode::QR_MODE_8, 1); Is it possible to display 'QR Code' directly without saving it to a file.
Joel Bodenmann Posted October 31, 2023 Report Posted October 31, 2023 Yes, that is certainly possible. When it comes to displaying images there are two things to consider: The format/encoding of the image itself. This happens through the GDISP image API. The way you're loading the image. This happens via the GFILE abstraction module. There are plenty of options to choose for both of these points. For the first point, you might translate the QRcode into a NATIVE image format which is easy to achieve as it's the most basic way of representing an image. If you'd like to have more control, you can implement a custom image format wrapping your QRcode object directly. For the second point, you might be able to use the existing MEMFS implementation to load the image from memory. If that is not sufficient, there are provisions for RAMFS. If your underlying system already provides a native filesystem interface with the ability to handle in-memory files you can use NATIVEFS.
Joel Bodenmann Posted October 31, 2023 Report Posted October 31, 2023 Given that your QRcode object consists of a width-by-width array of 8-bit values for each "pixel", you might just as well render it using gdispFillArea() and bypass all the image non-sense if the QR-Code is not needed for an extended period of time.
Vikash Posted November 2, 2023 Author Report Posted November 2, 2023 Hi @Joel Bodenmann, Thank you. Can you please share some example how I can use gdispFillArea() to show QR Code. I am using below to get QR encoded string. QRcode *qr = QRcode_encodeString("Data", 0, QRecLevel::QR_ECLEVEL_M, QRencodeMode::QR_MODE_8, 1);
Joel Bodenmann Posted November 2, 2023 Report Posted November 2, 2023 The QRcode type contains an array representing a width*width grid of cells making up the QR code. All you have to do is writing a simple function accepting a const pointer to a QRcode and the size of one QR code cell in pixel. Then clear the drawing area (i.e. with white color), iterate over the array/grid and drawing a black rectangle of the specified size for each cell in the QR code that needs to be black.
Vikash Posted November 10, 2023 Author Report Posted November 10, 2023 Hi @Joel Bodenmann Thanks for your reply. As of now I am generating png file with QR Data. I am using below logic to create a png file. Here, size = qr->width; const int red = 255; const int green = 255; const int blue = 255; for (int y = 0; y < size; ++y) { std::unique_ptr<png_byte[]> row(new png_byte[RGB * size * img_size]); for (int x = 0; x < size; ++x) { int idx = y * size + x; int bit = (qr->data[idx] & 1); for (int i = 0; i < img_size; ++i) { for (int j = 0; j < img_size; ++j) { row[3 * (x * img_size + j) + 0] = bit * red; .... } } } for (int i = 0; i < img_size; ++i) { png_write_row(png, row.get()); } } png_write_end(png, info); Can you please suggest how to achieve this without storing data into png file? I am not able to figure out how to display this in-memory QR Data without using png file.
Joel Bodenmann Posted November 10, 2023 Report Posted November 10, 2023 If you managed to get it working with your PNG approach you'll definitely be able to get it working by directly rendering to a display surface as that is easier (no need to mess with PNG). Instead of writing to a PNG buffer, you'd be iterating the QRcode array the same way but you're directly rendering each QRcode cell to a display surface. This can either be your physical display or a pixmap. The approach should be very simple: Clear the display area which will be occupied by the QRcode using gdispFillArea() For each cell in the QRcode leave it either blank (clear color) or color it in the opposite color as needed using gdispFillArea() Done Given that this is a free public support forum we maintain in our spare time we're usually not able to write actual code for customers. Please feel free to get in touch regarding commercial support if desired.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now