2007/05/26

簡單取得GIF長寬

沒想到GIF的長寬 這麼簡單取得,比較特別的是長寬的取得是前後交換
以下是程式碼,請參考




bool GetGifWidthHeight(const wxChar* buf,int size,int&Width,int& Height,bool& ReadWidthHeight)
{
if(size<10)
{
ReadWidthHeight=false;
return false;
}

char Head[7];

memcpy(&Head,&buf[0],sizeof(wxChar)*6);

ReadWidthHeight=false;

if(strncmp( Head, "GIF89a", 6 )==0)
{
ReadWidthHeight=true;
}
else if(strncmp( Head, "GIF87a", 6 )==0)
{
ReadWidthHeight=true;
}
else
{
ReadWidthHeight=true;
return false;
}

Width=(BYTE)buf[7]<<8 | (BYTE)buf[6];
Height=(BYTE)buf[9]<<8 | (BYTE)buf[8];

return true;
}


以上 , 不負責讀取所有格式,另有問題概不負責.
歡迎轉載並請標明出處.謝謝


參考:
(1)
http://www.google.com/codesearch?hl=en&q=+lang:c%2B%2B+read+gif+GIF87a+-img+show:iBviMvVRkiM:OFbzHTlzfvE:iCimjISyEyE&sa=N&amp;cd=9&ct=rc&cs_p=http://ftp.sayclub.com/pub/X/KDE/snapshots/kdegraphics.tar.bz2&cs_f=kdegraphics-662419/kfile-plugins/gif/kfile_gif.cpp#a0


(2)
http://www.google.com/codesearch?hl=en&q=+lang:c%2B%2B+read+gif+GIF87a+-img+show:UWpAtBfjvQQ:_U9kG32Kep4:eT79gmuydxg&sa=N&amp;cd=13&ct=rc&cs_p=ftp://ftp.trolltech.com/qt/source/qt-x11-opensource-4.0.0-b2.tar.bz2&cs_f=qt-x11-opensource-4.0.0-b2/src/plugins/imageformats/gif/qgifhandler.cpp#a0


沒有留言: