ccdot写于2008-9-17 13:39:29
protected static bool IsValidGif(byte[] source)
{
if (source == null || source.Length < 6)
return false;
byte[] GIF = new byte[6];
GIF[0] = 0x47;
GIF[1] = 0x49;
GIF[2] = 0x46;
GIF[3] = 0x38;
GIF[4] = 0x39;
GIF[5] = 0x61;
bool valid = true;
int nIndex = 0;
foreach(byte bTmp in GIF)
{
if(bTmp!=source[nIndex])
{
valid = false;
break;
}
nIndex++;
}
return valid;
}
protected static bool IsValidJpgOrJpeg(byte[] source)
{
if (source == null || source.Length < 10)
return false;
byte[] Jpg=new byte[4];
Jpg[0] = 0xff;
Jpg[1] = 0xd8;
Jpg[2] = 0xff;
Jpg[3] = 0xd9;
if (source[0] == Jpg[0] && source[1] == Jpg[1] && source[source.Length - 2] == Jpg[2] && source[source.Length - 1] == Jpg[3])
return true;
else
return false;
}