cFileBmp := MEMOREAD("image.bmp")
txtBmp := Text2Hex(cFileBmp)
oData:Image := txtBmp // save to blob field
...
...
txtBmp := oData:Image // read bmp file
cFileBmp := Hex2Txt(txtBmp)
MEMOWRITE("image.bmp", cFileBmp)
oBmp := LoadBmp("image.bmp")
....
..
.
//-------------------------------------------------------------------------------------------
Function Text2Hex(cFile) // Str2Hex(cFile)
local nLen, nCont, cChr, cBin
cBin := ""
nLen := LEN(cFile)
FOR nCont := 1 TO nLen
cChr := SUBSTR(cFile, nCont, 1)
cBin := cBin + STRTOHEX(cChr)
NEXT nCont
Return(cBin)
//-------------------------------------------------------------------------------------------
Function Hex2Text(cFile) // Hex2Str(cFile)
local nLen, nCont, cChr, cBin
cBin := ""
nLen := LEN(cFile)
FOR nCont := 1 TO nLen STEP 2
cChr := SUBSTR(cFile, nCont, 2)
cBin := cBin + HEXTOSTR(cChr)
NEXT nCont
Return(cBin)
//====================================================================================================
#pragma BEGINDUMP
#include "hbapi.h"
#include "hbapiitm.h" //#include "hbfast.h"
#include "hbstack.h"
#include "hbdefs.h"
#include "hbvm.h"
#include "hbapierr.h"
HB_ULONG HB_EXPORT hb_hextonum(char *cHex)
{
HB_ULONG ulNum = 0;
char c;
int iDigit;
while ( *cHex && (*cHex == ' ') ) cHex++;
while ( *cHex )
{
ulNum <<= 4;
c = *cHex;
if ( c >= '0' && c <= '9' )
{
iDigit = c - '0';
}
else if ( c >= 'A' && c <= 'F' )
{
iDigit = c - 'A' + 10;
}
else if ( c >= 'a' && c <= 'f' )
{
iDigit = c - 'a' + 10;
}
else
{
ulNum = 0;
break;
}
ulNum += iDigit;
cHex++;
}
return ulNum;
}
HB_FUNC( NUMTOHEX )
{
int iDigit;
char ret[ 33 ];
int iLen, iDefaultLen;
HB_ULONG ulNum;
if( ISNUM( 2 ) )
{
iLen = hb_parni( 2 );
iLen = ( iLen < 1 ) ? 1 : ( ( iLen > 32 ) ? 32 : iLen );
iDefaultLen = 0;
}
else
{
iLen = 32;
iDefaultLen = 1;
}
if( ISNUM( 1 ) )
{
ulNum = hb_parnint( 1 );
}
else if ( ISPOINTER( 1 ) )
{
ulNum = (HB_PTRDIFF) hb_parptr( 1 );
}
else
{
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, "NUMTOHEX", 2, hb_paramError( 1 ), hb_paramError( 2 ) );
return;
}
ret[ iLen ] = '\0';
do {
iDigit = (int) ( ulNum & 0x0F );
ret[ --iLen ] = iDigit + ( iDigit < 10 ? '0' : 'A' - 10 );
ulNum >>= 4;
} while ( iDefaultLen ? ulNum > 0 : iLen > 0 );
hb_retc( &ret[ iLen ] );
}
HB_FUNC( HEXTONUM )
{
if( ! ISCHAR(1) )
{
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, "HEXTONUM", 1, hb_paramError( 1 ) );
return;
}
hb_retnint( hb_hextonum( hb_parc( 1 ) ) );
}
HB_FUNC( STRTOHEX )
{
char *cOutBuf;
char *cStr;
char *c;
char *cSep = "";
unsigned char ucChar;
ULONG ul, ulLen, ulLenSep = 0;
int iDigit;
if( ! ISCHAR(1) )
{
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, "STRTOHEX", 2, hb_paramError( 1 ), hb_paramError( 2 ) );
return;
}
if ( ISCHAR( 2 ) )
{
cSep = hb_parc( 2 );
ulLenSep = hb_parclen( 2 );
}
cStr = hb_parc( 1 );
ulLen = hb_parclen( 1 );
c = cOutBuf = (char*) hb_xgrab( ulLen * 2 + ( ulLen - 1 ) * ulLenSep + 1 );
for( ul = 0; ul < ulLen; ul++ )
{
if ( ulLenSep && ul )
{
memcpy( c, cSep, ulLenSep );
c += ulLenSep;
}
ucChar = (unsigned char) cStr[ ul ];
iDigit = (int) ( ucChar & 0x0F );
c[ 1 ] = iDigit + ( iDigit < 10 ? '0' : 'A' - 10 );
ucChar >>= 4;
iDigit = (int) ucChar;
c[ 0 ] = iDigit + ( iDigit < 10 ? '0' : 'A' - 10 );
c += 2;
}
hb_retclen( cOutBuf, c - cOutBuf );
hb_xfree( cOutBuf );
}
HB_FUNC( HEXTOSTR )
{
char *cOutBuf, *cStr;
char c;
int iByte, iFirst;
ULONG ul, ulLen, ulPos, ulAlloc;
if( ! ISCHAR(1) )
{
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, "HEXTOSTR", 1, hb_paramError( 1 ) );
return;
}
cStr = (char *) hb_parc( 1 );
ulLen = hb_parclen( 1 );
ulAlloc = (int) ( ulLen / 2 );
cOutBuf = (char *) hb_xgrab( ulAlloc + 1 );
ulPos = 0;
iByte = 0;
iFirst = 1;
for ( ul = 0; ul < ulLen; ul++ )
{
iByte <<= 4;
c = *cStr++;
if ( c >= '0' && c <= '9' )
{
iByte += c - '0';
}
else if ( c >= 'A' && c <= 'F' )
{
iByte += c - 'A' + 10;
}
else if ( c >= 'a' && c <= 'f' )
{
iByte += c - 'a' + 10;
}
else
{
continue;
}
iFirst ^= 1;
if ( iFirst )
{
cOutBuf[ ulPos++ ] = (char) iByte;
iByte = 0;
}
}
hb_retclen( cOutBuf, ulPos );
hb_xfree( cOutBuf );
}
#pragma ENDDUMP