Memory Device - Serialize BMP (Sample)
GUI_MEMDEV_SerializeBMP.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | GUI_MEMDEV_SerializeBMP.c |
This sample shows how bitmap files can be created from the contents of a memory device. It supports both the usage of Windows file system and emFile.
Code
/*********************************************************************
* SEGGER Microcontroller GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2020 SEGGER Microcontroller GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : GUI_MEMDEV_SerializeBMP.c
Purpose : Shows how bitmap files can be created from the contents
of a memory device in emWin.
This sample supports both usage in the Windows
Simulation as well as usage on a target device using
emFile.
Requirements: WindowManager - ( )
MemoryDevices - (x)
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#ifdef WIN32
#include "Windows.h"
#else
#include "FS.h"
#endif
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#ifdef WIN32
#define FILE_PATH "C:\\Temp\\GUI_MEMDEV_SerializeBMP.bmp"
#else
#define FILE_PATH "GUI_MEMDEV_SerializeBMP.bmp"
#endif
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _WriteByteToFile
*/
static void _WriteByteToFile(U8 Data, void * p) {
#ifdef WIN32
U32 nWritten;
WriteFile(*((HANDLE *)p), &Data, 1, &nWritten, NULL);
#else
FS_FWrite(&Data, sizeof(Data), 1, ((FS_FILE *)p));
#endif
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
#ifdef WIN32
HANDLE hFile;
#else
FS_FILE * pFile;
char acVolumeName[10];
#endif
GUI_MEMDEV_Handle hMem;
//
// Init GUI.
//
GUI_Init();
//
// Create memory device
//
hMem = GUI_MEMDEV_CreateFixed32(0, 0, 100, 100);
//
// Select memory device
//
GUI_MEMDEV_Select(hMem);
//
// Execute drawing operations
//
GUI_SetColor(GUI_RED);
GUI_FillCircle(50, 50, 20);
//
// Clear selection of memory device
//
GUI_MEMDEV_Select(0);
#ifdef WIN32
//
// Create file handle
//
hFile = CreateFile(FILE_PATH, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
//
// Serialize BMP
// The function points to the write routine and the file handle
//
GUI_MEMDEV_SerializeBMP(hMem, _WriteByteToFile, &hFile);
//
// Close file handle
//
CloseHandle(hFile);
#else
//
// Start emFile
//
FS_Init();
//
// Enable long file name support
//
FS_FAT_SupportLFN();
//
// Mount volume
//
FS_GetVolumeName(0, acVolumeName, sizeof(acVolumeName));
if (FS_Mount(acVolumeName) > 0) {
//
// Open file
//
pFile = FS_FOpen(FILE_PATH, "wb");
}
//
// Serialize BMP by calling the function and passing the _WriteByteToFile callback
//
GUI_MEMDEV_SerializeBMP(hMem, _WriteByteToFile, pFile);
//
// Close file
//
FS_FClose(pFile);
#endif
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/