SRC: Получение ширины/высоты EPS-файла
От: Flamer Кипр http://users.livejournal.com/_flamer_/
Дата: 30.07.02 12:39
Оценка: 22 (3)
Сабж, собственно... Функция получает ширину/высоту картинки, сохраненной в формате EPS:


//---------------------------------------------------------------------------
bool GetEPSDim(const char* FileName, int& Width, int& Height)
{
Width = Height = -1;

FILE* hFile = fopen(FileName,"rb");
if(!hFile) return false;

bool ImageDataFound = false; // image data exists flag
unsigned char bNext=0;
unsigned char bTag[10]={0};


while(!feof(hFile)) {

 if(!fread(&bNext,1,1,hFile)) {
    fclose(hFile);
    return false;
    }

  if(bNext=='%') { // possible image data follows

     if(fread(bTag,1,9,hFile)!=9) {
       fclose(hFile);
       return false;
     }

     bTag[9]=0;
     if(strcmpi((char*)bTag,"ImageData")==0) {
       ImageDataFound = true; // find it!
       break;
      } else {
        if(fseek(hFile,-9,SEEK_CUR)!=0) {
          fclose(hFile);
          return false;
         }
      } // else
   } // if(bNext=='%')
} // while

if(!ImageDataFound) { // bad file format or image data not present
    fclose(hFile);
    return false;
    }


while( !feof(hFile) ) {

 if(!fread(&bNext,1,1,hFile)) {
    fclose(hFile);
    return false;
    }

    if(bNext!=':' && bNext!=' ') {
        break;
    }
} // while

char cBuf[40]={0};
char* p = cBuf;
*p++ = bNext;

// get width
while(bNext!=' ') {
 if(!fread(&bNext,1,1,hFile)) {
    fclose(hFile);
    return false;
   }
   if(bNext!=' ') *p++ = bNext;
}

Width = atoi(cBuf);


// get height
memset(cBuf,0,40);
p = cBuf;
while( !feof(hFile) ) {
 if(!fread(&bNext,1,1,hFile)) {
   fclose(hFile);
   return false;
  }
  if(bNext==' ') break;
  *p++ = bNext;
} // while

Height = atoi(cBuf);

fclose(hFile);
return true;
}
//---------------------------------------------------------------------------


Пример использования:

int Width, Height;
GetEPSDim("C:\\test.eps",Width,Height); // в Width - ширина, в Height - высота
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.