Reading Binary Data.

  • Thread starter Thread starter Ady
  • Start date Start date
A

Ady

Hi,

I am trying to create an editor and the structure of our existing files are
as follows.

In C# how would I read the following binary data from a file and convert it
into usable data.

// c code
typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char version;
TRIANGLE[];
}

Any help appreciated

Ady.
 
Ady,
You can use Serialization or System.IO.BinaryReader.

With Serialization the system does most of the work for you, with
BinaryReader & BinaryWriter you have to do more of the work.

For details on Serialization see:

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

For BinaryReader see:
http://msdn.microsoft.com/library/d.../html/frlrfSystemIOBinaryReaderClassTopic.asp

Hope this helps
Jay
 
Thanks for this.

I just have one more question if the format of the file is as follows,

typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char Ver;
char header[90];
unsigned int offsetTextures;
TRIANGLE tri[];
} MyFile;

How could I pull out the value off offsetTextures and add it on to the
beginning of the file to get the offset to the start of my texture data.

an example would be much appreciated.

Ady.


Jay B. Harlow said:
Ady,
You can use Serialization or System.IO.BinaryReader.

With Serialization the system does most of the work for you, with
BinaryReader & BinaryWriter you have to do more of the work.

For details on Serialization see:

http://msdn.microsoft.com/msdnmag/issues/02/04/net/
http://msdn.microsoft.com/msdnmag/issues/02/07/net/
http://msdn.microsoft.com/msdnmag/issues/02/09/net/

For BinaryReader see:
http://msdn.microsoft.com/library/d.../html/frlrfSystemIOBinaryReaderClassTopic.asp

Hope this helps
Jay


Ady said:
Hi,

I am trying to create an editor and the structure of our existing files are
as follows.

In C# how would I read the following binary data from a file and convert it
into usable data.

// c code
typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char version;
TRIANGLE[];
}

Any help appreciated

Ady.
 
Back
Top