I have an image, including image header, stored in a c# byte array (byte []).
The header is at the beginning of the byte array.
If I put the header in a struct (as I did in c++) it looks like this:
typedef struct RS_IMAGE_HEADER
{
long HeaderVersion;
long Width;
long Height;
long NumberOfBands;
long ColorDepth;
long ImageType;
long OriginalImageWidth;
long OriginalImageHeight;
long OffsetX;
long OffsetY;
long RESERVED[54];
long Comment[64];
} RS_IMAGE_HEADER;
How can I do it in c#, how can I get and use all the data in the image header (that stored in the beginning of the byte array)?
Thanks
Structs are perfectly fine in C#, so there should be no issue with the struct pretty much exactly as you’ve written it, though you might need to add permission modifiers such as
public. To convert byte arrays to other primitives, there are a very helpful class of methods that include ToInt64() that will help you convert an array of bytes to another built in type (in this caselong). To get the specific sequences of array bytes you’ll need, check out this question on various techniques for doing array slices in C#.