405 views
in Platform Packages by

Hello!

I aim to create a QR-code bitmap by using the function EwLoadExternBitmap. The colors of the QR-code should be two of my defined color constants. However, there are variants of these colors for light- and dark mode. Firstly, how can I extract the RGB-values from my defined color constants? Secondly, is there a simple way to fetch these RGB-values based on my currently active styles? I understand that I can get styles by using EwGetStyles, but I would like the code to resolve which variant of a color that is in use dynamically so that I don't have to modify this code if more styles are added.

Regards,
Måns

1 Answer

+1 vote
by

Hi Måns,

evaluating the styles and accessing the constants would be possible. If you want to follow this approach, just implement the desired operation in Chora and analyze the resulting C code. Then you can copy and reuse the code.

Nevertheless, I would recommend other approach:

1. Let the EwLoadExternBitmap() function create an ALPHA8 bitmap (see also Bitmap Color format EW_PIXEL_FORMAT_ALPHA8). It means a bitmap with opacity information only (no color information). In such bitmap, the opaque parts of the QR code could have the opacity 255, the transparent parts the opacity 0.

See also the section Access Intrinsics implemented in foreign Modules. It demonstrates the integration of a QR code encoder. When you download the example project found at the end of this section, you will find in one of its sub-folders a file named main.c. This file implements EwLoadExternBitmap() to create a QR ALPHA8 bitmap using the QR-code generator library.

2. In your Embedded Wizard project, when the bitmap is displayed in an Image view, you can configure which color should be used for the opaque areas. See the property Color of the Image view.

3. Add a Filled Rectangle view to the component containing the Image view where the QR bitmap is shown. Arrange the rectangle view behind the Image view and its size to correspond to the size of the QR bitmap.

4. Configure the color of the Filled rectangle view.

The color of the opaque areas of the QR code is determined by the Image view. The color of the transparent areas is determined by the filled rectangle. The colors can be changed at the runtime and if desired can depend on the light/dark theme.

I hope the idea helps you further.

Best regards

Paul Banach

 

by
Thank you for the great tip. This solution is perfect!

Ask Embedded Wizard - Archive

Welcome to the Ask Embedded Wizard archive. This community forum served us well for many years, but we've evolved our support approach!

Your resources:

The Embedded Wizard Online Documentation provides comprehensive documentation, tutorials, examples and ready-to-use software packages.

For dedicated assistance, explore our Embedded Wizard Product Support.

You can still browse the valuable discussions from our community history here.

Embedded Wizard Website | Privacy Policy | Imprint

...