Jump to content

Draw QR Code


Vikash

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

  1. Clear the display area which will be occupied by the QRcode using gdispFillArea()
  2. For each cell in the QRcode leave it either blank (clear color) or color it in the opposite color as needed using gdispFillArea()
  3. 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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...