ReadTagMemory example for C++ Builder
#define DATACOUNT 4
void __fastcall TForm1::Button1Click(TObject *Sender)
{
L_INT nRet;
L_UINT16 LogoPosition= 0x8001; /* my private tag */
Variant vTagData;
Variant vSavedData;
L_HANDLE hFileInMemory= NULL; /* memory handle for the file */
L_INT32 nMemSize= 0; /* size of the file in memory */
vTagData= VarArrayCreate(OPENARRAY(int,(0,DATACOUNT-1)),varWord);
// initialize the array
vTagData.PutElement(5,0);
vTagData.PutElement(5,1);
vTagData.PutElement(24,2);
vTagData.PutElement(37,3);
/* Set the tag data to be saved */
LEADImage1->SetTag( LogoPosition, TAG_SSHORT, DATACOUNT, vTagData );
/* Save the image as a TIFF file in memory */
LEADImage1->SaveMemory(hFileInMemory, FILE_TIF, LEADImage1->BitmapBits, 0, nMemSize );
/* Get the tagged data */
nRet= LEADImage1->ReadTagMemory( hFileInMemory, nMemSize, 1, LogoPosition );
if ( nRet == SUCCESS )
{
/* Display a message showing the data */
if ( (LEADImage1->GetTagType(LogoPosition) == TAG_SSHORT) && (LEADImage1->GetTagCount(LogoPosition) == DATACOUNT) )
{
vSavedData= LEADImage1->GetTagData(0);
ShowMessage ( "X = " + IntToStr((int)vSavedData.GetElement(0)) + "\n" +
"Y = " + IntToStr((int)vSavedData.GetElement(1)) + "\n" +
"nWidth = " + IntToStr((int)vSavedData.GetElement(2)) + "\n" +
"nHeight = " + IntToStr((int)vSavedData.GetElement(3)) );
}
}
/* Free memory that we no longer need */
if (hFileInMemory != NULL )
GlobalFree ((void*)hFileInMemory );
}