Available in the LEADTOOLS Imaging toolkit. |
GetArrayInfo example for C++ 5.0 and later
// This example
// 1. loads a file into a memory buffer
// 2. Calls GetInfoMemory
// 3. Displays information about the file in memory
void CGetArrayInfoDlg::OnButton1()
{
CString strFormat;
int nWidth;
int nHeight;
int nBpp;
int nPage;
long nSizeDisk;
long nSizeMem;
CString strCompress;
int nFormat;
CString strMsg;
int nTotalPages;
int xRes, yRes;
COleVariant MyVar;
long lSize;
// Create the memory file
HFILE hFile;
HGLOBAL hData=NULL;
void FAR* pData=NULL;
SAFEARRAY FAR *psa;
SAFEARRAYBOUND rgsabound[1];
MyVar.Clear();
hFile = _lopen("d:\\work\\images\\mtif.tif", OF_READ);
lSize = _llseek(hFile, 0, SEEK_END);
_llseek(hFile, 0, SEEK_SET);
hData = GlobalAlloc(GMEM_MOVEABLE, lSize);
pData = GlobalLock(hData);
_lread(hFile, pData, lSize);
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = lSize;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
SafeArrayLock(psa);
memcpy(psa->pvData, pData, lSize);
SafeArrayUnlock(psa);
V_VT(&MyVar) = (VT_ARRAY | VT_UI1);
V_ARRAY(&MyVar) = psa;
GlobalUnlock(hData);
GlobalFree(hData);
m_LEAD1.GetArrayInfo(MyVar, 1, lSize, FILEINFO_TOTALPAGES);
// Read the updated properties
nFormat = m_LEAD1.GetInfoFormat();
nWidth = (int)m_LEAD1.GetInfoWidth();
nHeight = (int)m_LEAD1.GetInfoHeight();
nBpp = m_LEAD1.GetInfoBits();
nPage = m_LEAD1.GetInfoPage();
nSizeDisk = m_LEAD1.GetInfoSizeDisk();
nSizeMem = m_LEAD1.GetInfoSizeMem();
strCompress = m_LEAD1.GetInfoCompress();
xRes = m_LEAD1.GetInfoXRes();
yRes = m_LEAD1.GetInfoYRes();
nTotalPages = m_LEAD1.GetInfoTotalPages();
// Translate the meaning of the format constant
strFormat = "Unknown format";
switch( nFormat)
{
case FILE_TIF:
strFormat = "TIF";
break;
case FILE_PCX:
strFormat = "ZSoft PCX";
break;
case FILE_GIF:
strFormat = "CompuServe GIF";
break;
case FILE_TGA:
strFormat = "TARGA";
break;
case FILE_PNG:
strFormat = "Portable Network Graphics";
break;
case FILE_PSD:
strFormat = "Adobe Photoshop 3.0";
break;
case FILE_BMP:
strFormat = "Windows BMP";
break;
case FILE_OS2:
strFormat = "OS/2 BMP version 1.x";
break;
case FILE_OS2_2:
strFormat = "OS/2 BMP version 2.x";
break;
case FILE_WMF:
strFormat = "Windows Meta File";
break;
case FILE_EPS:
strFormat = "Encapsulated PostScript";
break;
case FILE_PCT:
strFormat = "Macintosh Pict";
break;
case FILE_MSP:
strFormat = "Microsoft Paint";
break;
case FILE_IMG:
strFormat = "GEM Image";
break;
case FILE_PCD:
strFormat = "Kodak PhotoCD";
break;
case FILE_EPSTIFF:
strFormat = "Encapsulated PostScript with an embedded TIFF file";
break;
}
strMsg.Format("Page = %d of %d\nFormat = %s\nWidth and Height [%d, %d]\nMemory Size = %d\nDisk Size = %d\nBits per pixel = %d\n XRes,YRes = [%d, %d]\n",
nPage, nTotalPages,
strFormat,
nWidth, nHeight,
nSizeMem,
nSizeDisk,
nBpp,
xRes, yRes);
MessageBox(strMsg, "File Info");
}