Skip to content

Python utility to convert any file to hex, and export to C Code ( *.cpp; *.c ). Used to D3D Create Texture ( D3DXCreateTextureFromFileInMemory ) or other occasions in need in C++ projects.

License

Notifications You must be signed in to change notification settings

BrandTime/Any_file_exported_to_hex_C-Code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Any file exported to hex(C-Code)

Python utility to convert any file to hex, and export to C Code ( *.cpp; *.c ). Used to D3D Create Texture ( D3DXCreateTextureFromFileInMemory ) or other occasions in need in C++ projects.

Author:         Time Brand
Date:           August 7, 2019
License:        MIT Opensource License (see license.txt) 
Compatability:  Python 2/3
Version:        1.0.0

Any file exported to hex Overview

Python utility to convert any file to hex, and export to C Code ( *.cpp; *.c ). Used to D3D Create Texture ( D3DXCreateTextureFromFileInMemory ) or other occasions in need in C++ projects.

The command line is:

$ python FileExportToCCode.py infile

Where:

infile : Path to input . file.

Example 1:

$ python FileExportToCCode.py test1.png

Process the file test1.png. Export to a file with 16 hex bytes on each row(You can modify line 5 in the code to change the bytes on each row).

Output:

unsigned char test1[1547] = {
    0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
    0x00, 0x00, 0x01, 0xA4, 0x00, 0x00, 0x01, 0xA4, 0x08, 0x02, 0x00, 0x00, 0x00, 0xF1, 0x2E, 0xC6,
    0x62, 0x00, 0x00, 0x05, 0xD2, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9C, 0xEC, 0xD7, 0xC1, 0x6D, 0xE3,
    0x30, 0x00, 0x05, 0xD1, 0xF5, 0x42, 0x45, 0xB8, 0x0A, 0xB7, 0xE5, 0x9A, 0xDC, 0x96, 0xAB, 0xD0,
    0x91, 0x25, 0xE4, 0x96, 0x73, 0x10, 0x38, 0x24, 0xC4, 0x79, 0xAF, 0x01, 0x7E, 0x80, 0xD0, 0x40,
    0x3C, 0xC6, 0x18, 0xFF, 0x00, 0x76, 0xF7, 0x7F, 0xF5, 0x00, 0x80, 0x19, 0xC4, 0x0E, 0x48, 0x10,
    0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41,
    0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04,
    0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12,
    0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48,
    0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20,
    0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80,
    0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x38, 0x56, 0x0F, 0xB8, 0xB0, 0xF3, 0xFD, 0x5C, 0x3D,
    0xE1, 0xF3, 0xEE, 0x8F, 0xD7, 0xEA, 0x09, 0x9F, 0xE4, 0x8E, 0xF8, 0xE6, 0xCF, 0x0E, 0x48, 0x10,
    0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41,
    0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04,
    0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12,
    0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48,
    0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20,
    0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80,
    0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03,
    0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E,
    0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B,
    0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC,
    0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1,
    0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4,
    0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10,
    0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x38, 0xA6, 0x9D, 0x74,
    0xBE, 0x9F, 0xD3, 0xCE, 0x82, 0x8D, 0xED, 0xF7, 0x29, 0xDD, 0x1F, 0xAF, 0x09, 0xA7, 0xCC, 0x8B,
    0xDD, 0x96, 0xE6, 0x5C, 0x12, 0xBF, 0xB6, 0xDF, 0x05, 0xED, 0x57, 0xBA, 0x69, 0x3C, 0x63, 0x81,
    0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03,
    0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E,
    0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B,
    0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC,
    0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1,
    0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4,
    0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10,
    0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41,
    0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04,
    0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12,
    0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48,
    0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20,
    0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80,
    0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03,
    0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E,
    0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B,
    0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC,
    0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1,
    0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4,
    0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10,
    0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41,
    0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04,
    0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12,
    0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48,
    0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20,
    0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80,
    0x04, 0xB1, 0x03, 0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03,
    0x12, 0xC4, 0x0E, 0x48, 0x10, 0x3B, 0x20, 0x41, 0xEC, 0x80, 0x04, 0xB1, 0x03, 0x12, 0x8E, 0xD5,
    0x03, 0xAE, 0xED, 0x7C, 0x3F, 0x57, 0x4F, 0x00, 0x7E, 0xE4, 0x36, 0xC6, 0x58, 0xBD, 0xE1, 0xAA,
    0x94, 0x8E, 0x25, 0xEE, 0x8F, 0xD7, 0xEA, 0x09, 0x97, 0xE4, 0x19, 0x0B, 0x24, 0x88, 0x1D, 0x90,
    0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40,
    0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01,
    0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07,
    0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D,
    0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76,
    0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8,
    0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62,
    0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88,
    0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20,
    0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82,
    0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09,
    0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24,
    0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90,
    0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40,
    0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01,
    0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07,
    0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D,
    0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76,
    0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8,
    0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62,
    0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88,
    0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20,
    0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82,
    0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09,
    0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24,
    0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90,
    0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40,
    0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0xC2, 0x6D, 0x8C,
    0xB1, 0x7A, 0x03, 0xC0, 0x9F, 0xF3, 0x67, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82,
    0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09,
    0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24,
    0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90,
    0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40,
    0x82, 0xD8, 0x01, 0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01,
    0x09, 0x62, 0x07, 0x24, 0x88, 0x1D, 0x90, 0x20, 0x76, 0x40, 0x82, 0xD8, 0x01, 0x09, 0x62, 0x07,
    0x24, 0x7C, 0x05, 0x00, 0x00, 0xFF, 0xFF, 0xDD, 0x66, 0x1F, 0xE2, 0x11, 0x65, 0x45, 0xEA, 0x00,
    0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82 
};

About

Python utility to convert any file to hex, and export to C Code ( *.cpp; *.c ). Used to D3D Create Texture ( D3DXCreateTextureFromFileInMemory ) or other occasions in need in C++ projects.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published