Wednesday 15 June 2011

c - How can I read a BMP file and access its header info via a struct pointer without using #pragma pack or __atribute__((packed))? -


This is my code. I would like to know how to read "BMP" file and "OK" and then Read the header value without compelling for

  typedef struct __attribute __ ((pack)) {uint8_t magic [2]; / * Magic number used to identify BMP file: 0x42 0x4D (hex code points for B and M). The following entries are possible: BM - Windows 3.1x, 95, NT, etc ... BA - OS / 2 bitmap array CI - OS / 2 color icon CP - OS / 2 color pointer IC - OS / 2 mark PT - OS / 2 pointer * / Uint32_t filesz; Size of BMP file in / * bytes * / uint16_t creator1; / * Reserved * / Uint16_t creator2; / * Reserved * / Uint32_t Offset; / * Offset, that means starting a byte address, where bitmap data can be found. * Bmp_header_t; Fp = fopen ("input.bmp", "r"); Bmp_header_p = malloc (sizeof (bmp_header_t)); Fred (BMP_Header_P, Size (Chair), 14, FP); Printf ("magic number =% c% c \ n", bmp_header_p-> magic [0], bmp_header_p-> magic [1]); Printf ("file size =%" PRIu32 "\ n", bmp_header_p- & gt; files);    

You can not enter the fread () Structure Instead, you have to type fread () in your fields differently:

  if (fread (& header-> Magic [0], 2 , 1, Fp!) = 1) {// Error} If (Fred (and header-> Files, 4, 1, FP)! = 1) {// Error}   < / Div> 

No comments:

Post a Comment