About the IMAGE_SetPNG function running error

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • About the IMAGE_SetPNG function running error

      I need to create a window on the screen, create a TEXT control under the window to display a dynamic number, in order to avoid the refresh is flashing, add code in the main function:
      WM_SetCreateFlags(WM_CF_MEMDEV);
      However, after adding the background image, it can not be displayed (do not add the above function picture to display normal), run the error prompt:
      GUI_PNG.c:Error in _png_cexcept_errot().

      The detailed code is as follows, the picture code is attached, I look forward to the answer, thank you <3

      C Source Code

      1. #include "DIALOG.h"
      2. #include "backgrond.h"
      3. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      4. #define ID_IMAGE_0 (GUI_ID_USER + 0x01)
      5. #define ID_TEXT_0 (GUI_ID_USER + 0x02)
      6. #define ID_IMAGE_0_IMAGE_0 0x00
      7. #define RECOMMENDED_MEMORY (1024L * 160)
      8. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      9. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },
      10. { IMAGE_CreateIndirect, "Image_png", ID_IMAGE_0, 0, 0, 800, 480, 0, 0, 0 },
      11. { TEXT_CreateIndirect, "Text1", ID_TEXT_0, 30, 198, 100, 41, 0, 0x64, 0 },
      12. };
      13. static const void * _GetImageById(U32 Id, U32 * pSize) {
      14. switch (Id) {
      15. case ID_IMAGE_0_IMAGE_0:
      16. *pSize = sizeof(_acBackgrond);
      17. return (const void *)_acBackgrond;
      18. }
      19. return NULL;
      20. }
      21. static void _cbDialog(WM_MESSAGE * pMsg) {
      22. const void * pData;
      23. WM_HWIN hItem;
      24. U32 FileSize;
      25. switch (pMsg->MsgId) {
      26. case WM_INIT_DIALOG:
      27. WINDOW_SetBkColor(pMsg->hWin, GUI_GRAY);
      28. // Initialization of 'Image_png'
      29. hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_0);
      30. pData = _GetImageById(ID_IMAGE_0_IMAGE_0, &FileSize);
      31. IMAGE_SetPNG(hItem, pData, FileSize);
      32. // Initialization of 'Text1'
      33. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      34. TEXT_SetFont(hItem, GUI_FONT_D32);
      35. TEXT_SetTextColor(hItem, GUI_MAKE_COLOR(0x00FFFFFF));
      36. TEXT_SetText(hItem, "00");
      37. break;
      38. default:
      39. WM_DefaultProc(pMsg);
      40. break;
      41. }
      42. }
      43. // USER START (Optionally insert additional public code)
      44. void MainTask(void) {
      45. WM_HWIN hWin;
      46. WM_HWIN hText;
      47. char acText[3] = { 0 };
      48. int value=0;
      49. WM_SetCreateFlags(WM_CF_MEMDEV);
      50. GUI_Init();
      51. if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
      52. GUI_ErrorOut("Not enough memory available.");
      53. return;
      54. }
      55. hWin = GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      56. while (1) {
      57. GUI_Delay(10);
      58. sprintf(acText, "%2d", value++);
      59. hText = WM_GetDialogItem(hWin, ID_TEXT_0);
      60. TEXT_SetText(hText, acText);
      61. }
      62. }
      63. // USER END
      Display All
      Files
      • png_xx.zip

        (904.61 kB, downloaded 37 times, last: )

      The post was edited 1 time, last by OpFancy ().

    • Hi,

      On my end it is running just fine.

      How much memory did you spend emWin?

      Try to increase the memory allocated in GUIConf.c.

      The minimum amount of memory required for emWin to decompress PNGs is calculated as follows:

      App. RAM requirement = (xSize + 1) * ySize * 4 + 54 Kbytes

      Please note that the flag WM_CF_MEMDEV causes also an increase of the memory required. There are better solution to avoid flickering, e.g. multi buffering (with GUIDRV_Lin driver) or using a cache (with GUIDRV_FlexColor).

      Regards,
      Sven