cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically access images?

Tnguy.3
Associate III

How do I access image resources and change a control's background image? For example, I have a gauge with a style 0 (BITMAP_BLUE_GAUGES_ORIGINAL_GAUGE_BACKGROUND_STYLE_00_ID

according to the generated code) and I want the background to change to style 1 (BITMAP_BLUE_GAUGES_ORIGINAL_GAUGE_BACKGROUND_STYLE_01_ID) on a tap of a button.

I current have the button perform the following

void Screen1View::SetGaugeStyle(touchgfx::Bitmap s)
{
    gauge1.setBackground(s);
    gauge1.invalidate();
}

where s is touchgfx::Bitmap(BITMAP_BLUE_GAUGES_ORIGINAL_GAUGE_BACKGROUND_STYLE_00_ID);

(for testing purposes) which is the default image, but when I run the simulator, the gauge image (or rather background) is empty and gone.

What am I doing wrong? Also, how do I access other image resources programmatically?

3 REPLIES 3
Tnguy.3
Associate III

So I think I found my answer.

For why it wasn't working was because I was passing it the wrong bitmap id value.

For the accessing the image resource, you can call Bitmap(uint_16 imgID) where imgID is in BitmapDatabase.hpp

If anyone know this is wrong and can provide a correct answer, please let me know

MM..1
Chief III

Show too code where and how you call SetGaugeStyle(...)

And you can use images in project only. Designer not add unused images from widgets, but add all your images .

image1.setBitmap(touchgfx::Bitmap(BITMAP_***_ID));

For the first answer, I found out my mistake which was passing in the wrong bitmap. For the second answer, do we need to add all of our images we want to use into the design first, generate the code, and then we can use it? Rather than adding the image into the IDE?