How to read data structure from file

  • Thread starter Thread starter George Ter-Saakov
  • Start date Start date
G

George Ter-Saakov

Hi. I need to read and analyze the header of the JPG file

public struct _JFIFHeader
{
byte SOI1, SOI2; /* 00h Start of Image Marker */
byte APP01,APP02; /* 02h Application Use Marker */
short Length; /* 04h Length of APP0 Field */
byte Id1,Id2,Id3,Id4,Id5;
short Version; /* 07h JFIF Format Revision */
byte Units; /* 09h Units used for Resolution */
short Xdensity; /* 0Ah Horizontal Resolution */
short Ydensity; /* 0Ch Vertical Resolution */
byte XThumbnail; /* 0Eh Horizontal Pixel Count */
byte YThumbnail; /* 0Fh Vertical Pixel Count */
};

How do i read it from file?
FileStream.Read takes a byte array as a parameter? But i need to read the
data into variable with type _JFIFHeader?





Thanks.

George.
 
you can use an unsafe code block and "copy" a bytearray to this struct

or

you can use Reflection to read the individual values out of the file

So far those are the only two ways I've found to do this. I'd love to find
a better way myself.
 
Attach a BinaryReader to your FileStream and look in the documentation for
BinaryReader members
 
Back
Top