Reading Binary Data.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ady

    #1

    Reading Binary Data.

    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.


  • Jay B. Harlow [MVP - Outlook]

    #2
    Re: Reading Binary Data.

    Ady,
    You can use Serialization or System.IO.Binar yReader.

    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/de...ClassTopic.asp

    Hope this helps
    Jay


    "Ady" <adrian.hirst@t cm.co.uk> wrote in message
    news:uNxrE7TeDH A.736@TK2MSFTNG P11.phx.gbl...[color=blue]
    > Hi,
    >
    > I am trying to create an editor and the structure of our existing files[/color]
    are[color=blue]
    > as follows.
    >
    > In C# how would I read the following binary data from a file and convert[/color]
    it[color=blue]
    > 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.
    >
    >[/color]


    Comment

    • Ady

      #3
      Re: Reading Binary Data.

      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 [MVP - Outlook]" <Jay_Harlow@ema il.msn.com> wrote in message
      news:u4ifHCUeDH A.2756@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Ady,
      > You can use Serialization or System.IO.Binar yReader.
      >
      > 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:
      >[/color]
      http://msdn.microsoft.com/library/de...ClassTopic.asp[color=blue]
      >
      > Hope this helps
      > Jay
      >
      >
      > "Ady" <adrian.hirst@t cm.co.uk> wrote in message
      > news:uNxrE7TeDH A.736@TK2MSFTNG P11.phx.gbl...[color=green]
      > > Hi,
      > >
      > > I am trying to create an editor and the structure of our existing files[/color]
      > are[color=green]
      > > as follows.
      > >
      > > In C# how would I read the following binary data from a file and convert[/color]
      > it[color=green]
      > > 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.
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...