Hola ErYcK.
Verificar si el archivo es un Bitmap:
Código PHP:
bool IsBMPFile(char *filename) {
unsigned char buf[2];
TFileStream *fs = new TFileStream(filename, fmOpenRead);
fs->Read(buf, sizeof(buf));
fs->Free();
return buf[0]==0x42 && buf[1]==0x4D;
}
/* Llamada de ejemplo */
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (IsBMPFile("Imagen.bmp"))
ShowMessage("Es un archivo Bitmap");
}
Leer información de la cabecera:
Código PHP:
void GetBmpNfo(char *filename, TStrings *nfo) {
TFileStream *Stream = new TFileStream(filename, fmOpenRead);
unsigned char buf[2];
TBitmapFileHeader fh;
TBitmapInfoHeader ih;
nfo->Clear();
Stream->Read(&fh, sizeof(fh));
buf[0]=fh.bfType&0xFF;
buf[1]=fh.bfType>>8&0xFF;
if (buf[0]== 0x42 && buf[1]==0x4D) {
nfo->Add("Type : " + IntToHex(fh.bfType&0xFF,2) +
IntToHex(fh.bfType>>8&0xFF,2));
nfo->Add("File size : " + String(fh.bfSize));
nfo->Add("Ofset : " + String(fh.bfOffBits));
nfo->Add("Image size : " + String(ih.biSize));
nfo->Add("Width : " + String(ih.biWidth));
nfo->Add("Height : " + String(ih.biHeight));
nfo->Add("Planes : " + String(ih.biPlanes));
nfo->Add("Bit count : " + String(ih.biBitCount));
nfo->Add("Bit compression : " + String(ih.biCompression));
nfo->Add("Bit X per meter : " + String(ih.biXPelsPerMeter));
nfo->Add("Bit Y per meter : " + String(ih.biYPelsPerMeter));
nfo->Add("Color index table : " + String(ih.biClrUsed));
nfo->Add("Color index display: " + String(ih.biClrImportant));
}
Stream->Free();
}
/* Llamada de ejemplo */
void __fastcall TForm1::Button1Click(TObject *Sender)
{
GetBmpNfo("Imagen.bmp", ListBox1->Items);
}
Es claro que si tenes definidas las dos funciones es innecesaria la comprobación del tipo de archivo en la segunda, es decir:
Código PHP:
void GetBmpNfo(char *filename, TStrings *nfo) {
TFileStream *Stream = new TFileStream(filename, fmOpenRead);
TBitmapFileHeader fh;
TBitmapInfoHeader ih;
nfo->Clear();
Stream->Read(&fh, sizeof(fh));
nfo->Add("Type : " + IntToHex(fh.bfType&0xFF,2) +
IntToHex(fh.bfType>>8&0xFF,2));
nfo->Add("File size : " + String(fh.bfSize));
nfo->Add("Ofset : " + String(fh.bfOffBits));
nfo->Add("Image size : " + String(ih.biSize));
nfo->Add("Width : " + String(ih.biWidth));
nfo->Add("Height : " + String(ih.biHeight));
nfo->Add("Planes : " + String(ih.biPlanes));
nfo->Add("Bit count : " + String(ih.biBitCount));
nfo->Add("Bit compression : " + String(ih.biCompression));
nfo->Add("Bit X per meter : " + String(ih.biXPelsPerMeter));
nfo->Add("Bit Y per meter : " + String(ih.biYPelsPerMeter));
nfo->Add("Color index table : " + String(ih.biClrUsed));
nfo->Add("Color index display: " + String(ih.biClrImportant));
Stream->Free();
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
char *fname= "Imagen.bmp";
if (IsBMPFile(fname))
GetBmpNfo(fname, ListBox1->Items);
}
Saludos