private bool get_attributes_from_jpeg2000(string File)
{
try
{
// Get the height and width of this JPEG file
FileStream reader = new FileStream(File, FileMode.Open, FileAccess.Read);
int[] previousValues = {0, 0, 0, 0};
int bytevalue = reader.ReadByte();
int count = 1;
while (bytevalue != -1)
{
// Move this value into the array
previousValues[0] = previousValues[1];
previousValues[1] = previousValues[2];
previousValues[2] = previousValues[3];
previousValues[3] = bytevalue;
// Is this IHDR?
if ((previousValues[0] == 105) && (previousValues[1] == 104) &&
(previousValues[2] == 100) && (previousValues[3] == 114))
{
break;
}
// Is this the first four bytes and does it match the output from Kakadu 3-2?
if ((count == 4) && (previousValues[0] == 255) && (previousValues[1] == 79) &&
(previousValues[2] == 255) && (previousValues[3] == 81))
{
reader.ReadByte();
reader.ReadByte();
reader.ReadByte();
reader.ReadByte();
break;
}
// Read the next byte
bytevalue = reader.ReadByte();
count++;
}
// Now, read ahead for the height and width
Height = (ushort) ((((((reader.ReadByte()*256) + reader.ReadByte())*256) + reader.ReadByte())*256) + reader.ReadByte());
Width = (ushort) ((((((reader.ReadByte()*256) + reader.ReadByte())*256) + reader.ReadByte())*256) + reader.ReadByte());
reader.Close();
return true;
}
catch
{
return false;
}
}