Ver Mensaje Individual
  #2  
Antiguo 30-09-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola ErYcK.

Verificar si el archivo es un Bitmap:
Código PHP:
bool IsBMPFile(char *filename) {
  
unsigned char buf[2];

  
TFileStream *fs = new TFileStream(filenamefmOpenRead);
  
fs->Read(bufsizeof(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 *filenameTStrings *nfo) {
  
TFileStream *Stream = new TFileStream(filenamefmOpenRead);
  
unsigned char buf[2];
  
TBitmapFileHeader fh;
  
TBitmapInfoHeader ih;

  
nfo->Clear();
  
Stream->Read(&fhsizeof(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 *filenameTStrings *nfo) {
  
TFileStream *Stream = new TFileStream(filenamefmOpenRead);
  
TBitmapFileHeader fh;
  
TBitmapInfoHeader ih;

  
nfo->Clear();
  
Stream->Read(&fhsizeof(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(fnameListBox1->Items);

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita