473,325 Members | 2,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How to read data structure from file

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.
Nov 15 '05 #1
2 5105
Attach a BinaryReader to your FileStream and look in the documentation for
BinaryReader members

"George Ter-Saakov" <no****@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...
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.

Nov 15 '05 #2
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.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Michael Van Altena via .NET 247 | last post by:
I'm trying to figure out how to read a formatted binary file intoa structure definition in C#. I've tried using the"StructLayout" attribute with both LayoutKind.Explicit andLayoutKind.Sequential...
5
by: Vasilis Serghi | last post by:
Hi all, I am fairly new to C programming and I have come to a stand still. I am trying to create a program that will accept a user input and give the user an output depending on the contents of a...
5
by: Alejandro Lapeyre | last post by:
I am writing a class to wrap a RIFF file, so i have to read and decode some structured data on the file. For example, in the begining of file is a header: Public Structure RiffHeader Public...
3
by: Dave Coate | last post by:
Hello again, I am going to re-post a question. I got some excellent suggestions from Rob and Mattias on this but their ideas did not solve the problem. Here is the original post: ...
2
by: Eric | last post by:
Hi, I need to send data from a file into a structure. In Vb6 this was done like so. public Type Struct1 v1 as string v2 as string end type
8
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
5
by: Jens | last post by:
Hello, I have been looking for some C-code which listens on a user-defined port for incoming data traffic. When data is received, the data is written to a file. I found some C-code (server)...
11
by: waffle.horn | last post by:
Hi, if this makes sense i want to create a function that can be called so that it reads a single line from a file, then after using the information destroys it. Such that when the function is...
9
by: Hollywood | last post by:
Hello members of the comp.lang.c++, My log file is made of a set of 1000 following lines kind: 21/09/07 13:49:56,MW.SET.D_IGLS,2.000000 21/09/07 13:49:56,MW.SET.GNP_NT,7.000000 ..... ...
6
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: number of Data, Data array Suppose I have...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.