ReadTagMemory example for C++ 5.0 and later
void CTestDlg::OnReadTagMemory()
{
int nRet;
long hMem;
long lSize;
ILEADRasterVariant * pltRasVar = NULL;
CoCreateInstance(CLSID_LEADRasterVariant, NULL, CLSCTX_ALL,
IID_ILEADRasterVariant, (void **)&pltRasVar);
pltRasVar->Type = VALUE_STRING;
pltRasVar->StringValue
= "My text string";
m_pRasterIO->SetTag(32768, TAG_ASCII, 0, pltRasVar);
nRet = m_pRasterIO->SaveMemory(m_LEADRasterView.GetRaster(),
&hMem, FILE_TIF, m_LEADRasterView.GetRaster().GetBitmapBits(), QFACTOR_LEAD_0,
0, &lSize);
nRet = m_pRasterIO->ReadTagMemory
(hMem, 1, 32768, lSize);
GetAndDisplayTag(0);
pltRasVar->Release ();
}
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 = (long*)GlobalAlloc(GHND,pltRasVar->ItemCount);
for(long i=0; i<lTagCount; i++)
{
pData[i] = pltRasVar->GetShortItemValue(i);
}
for(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 = (long*)GlobalAlloc(GHND,pltRasVar->ItemCount);
for(long i=0; i<lTagCount; i++)
pData[i] = pltRasVar->GetShortItemValue(i);
for(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)((TCHAR *)pData)[i]); break;
case
TAG_SBYTE:
Str1.Format(TEXT("\r\nData(%d)
= %d"), i, (int)((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);
}