Difference between revisions of "ImageBox"

From uGFX Wiki
Jump to: navigation, search
(Created page with "The image box simply takes the GDISP image decoder features and wraps them around a GWIN widget. Therefore, please refer to the GDISP image and the GFILE documentation to lear...")
(No difference)

Revision as of 01:40, 30 June 2014

The image box simply takes the GDISP image decoder features and wraps them around a GWIN widget. Therefore, please refer to the GDISP image and the GFILE documentation to learn how to use it.


Animated Images

If you want to use animated images such as multi-frame GIF images, you have to enable the GWIN_NEED_IMAGE_ANIMATION in your gfxconf.h.


Example

The following example reads two images from a memory location (a BMP and an animated GIF) and displays them. The demo shows how GWIN automatically takes care about the animation.

#include "gfx.h"
 
#include "image_chibios.h"
#include "image_waterfall.h"
 
static GHandle   ghImage1, ghImage2;
 
static void createWidgets(void) {
	GWidgetInit	wi;
 
	// Apply some default values for GWIN
	wi.g.show = TRUE;
 
	// create the first image widget
	wi.g.x = 10; wi.g.y = 10; wi.g.width = 120; wi.g.height = 120;
	ghImage1 = gwinImageCreate(NULL, &wi.g);
	gwinImageOpenMemory(ghImage1, image_chibios);
 
	// create the second image widget
	wi.g.x = 160; wi.g.y = 10; wi.g.width = 120; wi.g.height = 120;
	ghImage2 = gwinImageCreate(NULL, &wi.g);
	gwinImageOpenMemory(ghImage2, image_waterfall);
 
	// optionally cache the images
	gwinImageCache(ghImage1);
	gwinImageCache(ghImage2);
}
 
int main(void) {
	// Initialize µGFX and the underlying system
	gfxInit();
 
	// Set the widget defaults
	gwinSetDefaultFont(gdispOpenFont("UI2"));
	gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
	gdispClear(White);
 
	// create the widget
	createWidgets();
 
	while(1) {
		gfxSleepMilliseconds(100);
	}
 
	return 0;
}
</syntaxhilight>