Adding GUI support for OLED screens 5: Picture controls
this blog link: http://blog.csdn.net/jdh99 , Author: jdh, reprint please specify.
Environment:
Host: WIN10
Development environment: MDK5.13
mcu:stm32f103
Description:This article defines a picture control. The OLED screen is a monochrome screen, so this picture control supports monochrome BMP images. converting a normal image to a monochrome picture can be BmpCvt.exe with a tool. Convert the converted BMP image to hex file, can be used Bin2C.exe. Both of these tools are emwin self-bringing tools.
Source:
The converted hex file is then organized into the following example format:
Battery0.c
/*** Copyright (c), 2015-2025* @file battery0.c* @brief Battery 0 grid icon * @author jdh* @date 2015/11/9* @verbatim * Description: * 1. Image format is bmp* 2. Picture size is 17*13* @endverbatim *//********************************************************************** header file ********* /#include "res.h"/******************************** Global variable ********************************************************************* */const unsigned char Res_battery0_bmp[114ul + 1] = {0x42, 0x4d, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0 X00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x0D, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x0 0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3F, 0xFF, 0x80, 0xFF, 0x20, 0x00, 0x80, 0x04, 0xE0, 0x00, 0x80, 0x00, 0xE0, 0x00, 0x80,0x00, 0xE0, 0x00, 0x80, 0x00, 0xE0, 0x00, 0x80, 0x00, 0xE0, 0x00, 0x80, 0x00, 0xE0, 0x00, 0x80, 0x00, 0x20, 0x00, 0x80, 0x XX, 0x3F, 0xFF, 0x80, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};/*************************** End of file ****************************/
Gui_widget_image.h
/*** Copyright (c), 2015-2025* @file gui_widget_image.h* @brief Picture Control header file * @author jdh* @date 2015/9/8*/#ifndef _gui_widget_ Image_h_#define _gui_widget_image_h_/********************************************************************** Header File * /#include "gui_interface.h"/************** Data Structure *************************************************** @brief picture control data structure */typedef struct _widget_image{//x axis position uint16_t x;//y axis position uint16_t y;// Horizontal size uint16_t xsize;//vertical size uint16_t ysize;//image address const uint8_t *ADDR;} *widget_image_handle;/********************************************************************** function **************** @brief Create the control text* @param x: Upper-Left x-coordinate * @param y: Upper-Left y-coordinate * @param Xsize: Horizontal Size * @param ysize: Vertical size */widget_image_handle gui_widget_image_create (uint16_t x,uint16_t y,uint16_t xsize, uint16_t ysize)/*** @brief setup diagramFilm * @param addr: Image address */void gui_widget_image_set_bmp (widget_image_handle handle,const uint8_t *addr); #endif
Gui_widget_image.c
/*** Copyright (c), 2015-2025* @file gui_widget_image.c* @brief Picture control main file * @author jdh* @date 2015/9/8*//****************** Header file ******************************************************** /#include "gui_widget_image.h" #include "gui_2d_lib.h" #include "stdlib.h" #include "string.h"/******** static function ********************************************* @brief control displays * @param handle: Control handle */static void Show (Widget_image_handle handle);/******* function ********************************************** @brief Create a control text* @param x: Upper-left corner x-coordinate * @param y: Upper-Left y-coordinate * @param xsize: Horizontal Size * @param ysize: Vertical Size * * Widget_image_handle gui_widget_image_create (uint16_t x,uint16_t y,uint16_t xsize,uint16_t ysize) {Widget_Image_ Handle handle;//Control Initialization Handle = malloc (sizeof (*handle)); handle->x = X;handle->y =Y;handle->xsize = Xsize;handle->ysize = Ysize;return handle;} /*** @brief Settings Picture * @param addr: Image address */void gui_widget_image_set_bmp (widget_image_handle handle,const uint8_t *addr) { HANDLE->ADDR = addr;//shows show (handle);} /*** @brief control displays * @param handle: Control handle */static void Show (Widget_image_handle handle) {//Clear area gui_fill_rect (Handle->x, Handle->y,handle->x + handle->xsize,handle->y + handle->ysize,0);//Display Gui_draw_bitmap (Handle->x, HANDLE->Y,HANDLE->ADDR);}
Test code:
Battery icon static Widget_image_handle widget_image_battery; Widget_image_battery = Gui_widget_image_create (106,0,17,13); Gui_widget_image_set_bmp (Widget_Image_Battery,Res_ Battery0_bmp);
Adding GUI support for OLED screens 5: Picture controls