SetTag example for C++ 5.0 and later
void CTest4Dlg::OnSetAndReadTag()
{
long *pData;
ILEADRasterVariant * pltRasVar = NULL;
CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL,
IID_ILEADRasterVariant, (void **)&pltRasVar);
// create a variant containing 4 elements. Note that this
// is needed only if we use the TAG_LONG tags...
pltRasVar->ItemCount = 4;
pltRasVar->Type = VALUE_LONG;
pltRasVar->LongItemValue (0) = 1;
pltRasVar->LongItemValue (1) = 2;
pltRasVar->LongItemValue (2) = 3;
pltRasVar->LongItemValue (3) = 127;
// set a tag using one of the following:
// m_pRasterIO->SetTag(32768, TAG_ASCII, 0, COleVariant("My text string"));
// m_pRasterIO->SetTag(32768, TAG_BYTE, 4, myArray);
// m_pRasterIO->SetTag(32768, TAG_DOUBLE, 4, myArray);
// m_pRasterIO->SetTag(32768, TAG_FLOAT, 4, myArray);
// m_pRasterIO->SetTag(32768, TAG_LONG, 4, myArray);
// m_pRasterIO->SetTag(32768, TAG_RATIONAL, 2, myArray);
// m_pRasterIO->SetTag(32768, TAG_SBYTE, 4, myArray);
// m_pRasterIO->SetTag(32768, TAG_SHORT, 4, myArray);
// m_pRasterIO->SetTag(32768, TAG_SLONG, 4, myArray);
// m_pRasterIO->SetTag(32768, TAG_SRATIONAL, 2, myArray);
// m_pRasterIO->SetTag(32768, TAG_SSHORT, 4, myArray);
m_pRasterIO->SetTag(32768, TAG_UNDEFINED, 4, pltRasVar);
// Write the tag. This file must already exist
m_pRasterIO->WriteTag("d:\\temp\\Test.tif", 1);
OnReadTag();
pltRasVar->Release ();
}
void CTestDlg::OnReadTag()
{
// read the tag back
m_pRasterIO->ReadTag("d:\\temp\\Test.tif", 1, 32768L);
GetAndDisplayTag(0);
}
void CTestDlg::GetAndDisplayTag(long lTag)
{
int uTagType = m_pRasterIO->GetTagType(lTag);
long lTagCount = m_pRasterIO->GetTagCount(lTag);
CString MsgString, Str1;
ILEADRasterVariant * pltRasVar = NULL;
CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL,
IID_ILEADRasterVariant, (void **)&pltRasVar);
pltRasVar = m_pRasterIO->GetTagData(lTag);
MsgString.Format(TEXT("Type = %d"), uTagType);
Str1.Format(TEXT("\r\nCount = %ld"), lTagCount);
MsgString += Str1;
if(uTagType == TAG_ASCII)
{
MsgString += TEXT("\r\nData = ");
MsgString += pltRasVar->StringValue;
}
else if(uTagType == TAG_RATIONAL || uTagType == TAG_SRATIONAL)
{
long *pData;
pData = GlobalAlloc(GHND,pltRasVar->ItemCount);
for(long i=0; i<lCount; i++)
pData[i] = pltRasVar->ShortItemValue(i);
for(long i = 0; i < lTagCount; i++)
{
Str1.Format(TEXT("\r\nData(%d) = %ld/%ld"), i, pData[i*2], pData[i*2+1]);
MsgString += Str1;
}
GlobalFree(pData);
}
else
{
long *pData;
pData = GlobalAlloc(GHND,pltRasVar->ItemCount);
for(long i=0; i<lCount; i++)
pData[i] = pltRasVar->ShortItemValue(i);
for(long i = 0; i < lTagCount; i++)
{
switch(uTagType)
{
case TAG_LONG:
Str1.Format(TEXT("\r\nData(%d) = %u"), i, ((unsigned long*)pData)[i]); break;
case TAG_SLONG:
Str1.Format(TEXT("\r\nData(%d) = %d"), i, ((signed long*)pData)[i]); break;
case TAG_SHORT:
Str1.Format(TEXT("\r\nData(%d) = %u"), i, (int)((unsigned short*)pData)[i]); break;
case TAG_SSHORT:
Str1.Format(TEXT("\r\nData(%d) = %d"), i, (int)((signed short*)pData)[i]); break;
case TAG_BYTE:
case TAG_UNDEFINED:
Str1.Format(TEXT("\r\nData(%d) = %u"), i, (int)((unsigned TCHAR *)pData)[i]); break;
case TAG_SBYTE:
Str1.Format(TEXT("\r\nData(%d) = %d"), i, (int)((signed TCHAR *)pData)[i]); break;
case TAG_FLOAT:
Str1.Format(TEXT("\r\nData(%d) = %f"), i, (double)((float*)pData)[i]); break;
case TAG_DOUBLE:
Str1.Format(TEXT("\r\nData(%d) = %f"), i, ((double*)pData)[i]); break;
}
MsgString += Str1;
}
GlobalFree(pData);
}
MessageBox(MsgString);
}
void CTestDlg::OnGetTag()
{
GetAndDisplayTag (32768L);
}