GetFileInfo example for C++ Builder
This example gets information about the specified file.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
AnsiString fname, cmp, cFmt, cMsg;
int pg, fmt, width, height, bps, xres, yres, sizd, sizm;
//Initialize variables
fname = "c:\\lead\\images\\image2.cmp";
pg =0;
//Update the variables
Lead1->GetFileInfo(fname, pg);
//Read the updated properties
fmt = Lead1->InfoFormat;
width = Lead1->InfoWidth;
height = Lead1->InfoHeight;
bps = Lead1->InfoBits;
xres = Lead1->InfoXRes;
yres = Lead1->InfoYRes;
pg = Lead1->InfoPage;
sizd = Lead1->InfoSizeDisk;
sizm = Lead1->InfoSizeMem;
cmp = Lead1->InfoCompress;
// Translate the meaning of the format constant
switch(fmt){
case FILE_PCX: cFmt = "ZSoft PCX"; break;
case FILE_GIF: cFmt = "CompuServe GIF"; break;
case FILE_TGA: cFmt = "TARGA"; break;
case FILE_PNG: cFmt = "Portable Network Graphics"; break;
case FILE_PSD: cFmt = "Adobe Photoshop 3.0"; break;
case FILE_BMP: cFmt = "Windows BMP"; break;
case FILE_OS2: cFmt = "OS/2 BMP version 1.x"; break;
case FILE_OS2_2: cFmt = "OS/2 BMP version 2.x"; break;
case FILE_WMF: cFmt = "Windows Meta File"; break;
case FILE_EPS: cFmt = "Encapsulated PostScript"; break;
case FILE_TIF: cFmt = "Tagged Image File Format (TIFF, TIFLZW, or CCITT file)"; break;
case FILE_TIF_JPEG: cFmt = "Tagged Image File with JPEG compression"; break;
case FILE_FAX_G3_1D: cFmt = "Raw FAX, compressed using CCITT group 3, 1 dimension"; break;
case FILE_FAX_G3_2D: cFmt = "Raw FAX, compressed using CCITT group 3, 2 dimensions"; break;
case FILE_FAX_G4: cFmt = "Raw FAX, compressed using CCITT group 4"; break;
case FILE_WFX_G3_1D: cFmt = "WinFax, compressed using CCITT group 3, 1 dimension"; break;
case FILE_WFX_G4: cFmt = "WinFax, compressed using CCITT group 4"; break;
case FILE_ICA_G3_1D: cFmt = "IOCA, compressed using CCITT group 3, 1 dimension"; break;
case FILE_ICA_G3_2D: cFmt = "IOCA, compressed using CCITT group 3, 2 dimensions"; break;
case FILE_ICA_G4: cFmt = "IOCA, compressed using CCITT group 4"; break;
case FILE_CMP: cFmt = "LEAD proprietary compression format"; break;
case FILE_LEAD_NOLOSS: cFmt = "LEAD lossless compression format"; break;
case FILE_JPEG: cFmt = "JPEG File Interchange Format"; break;
case FILE_WPG: cFmt = "WordPerfect"; break;
case FILE_RAS: cFmt = "Sun Raster"; break;
case FILE_CALS: cFmt = "CALS Raster"; break;
case FILE_MAC: cFmt = "MacPaint"; break;
case FILE_PCT: cFmt = "Macintosh Pict"; break;
case FILE_MSP: cFmt = "Microsoft Paint"; break;
case FILE_IMG: cFmt = "GEM Image"; break;
case FILE_PCD: cFmt = "Kodak PhotoCD"; break;
case FILE_EPSTIFF: cFmt = "Encapsulated PostScript with an embedded TIFF file"; break;
default: cFmt = "Unknown format";
}
// Create the message string
cMsg = fname + "\n";
cMsg = cMsg + "Page = " + IntToStr(pg) + " of " + IntToStr(Lead1
>InfoTotalPages) + "\n";
cMsg = cMsg + "Format = " + cFmt + "\n";
cMsg = cMsg + "Width = " + IntToStr(width) + "\n" + "Height = " + IntToStr(height) + "\n";
cMsg = cMsg + "Bits per pixel = " + IntToStr(bps) + "\n";
cMsg = cMsg + "Size in memory = " + IntToStr(sizm) + "\n";
cMsg = cMsg + "Size on disk = " + IntToStr(sizd) + "\n";
cMsg = cMsg + "X resolution = " + IntToStr(xres) + "\n" + "Y resolution = " + IntToStr(yres);
//Display the message box
Application->MessageBox(cMsg.c_str(), "File Info", MB_OK);
}