Lab_3
Lab_3
Write C-language code to extract header information of BMP Image. Verify your result
using matlab.
C-Code:
#include <stdio.h>
#include <stdint.h>
#pragma pack(1)
typedef struct {
uint16_t type;
uint32_t fileSize;
uint16_t reserved1;
uint16_t reserved2;
uint32_t offset;
uint32_t headerSize;
int32_t width;
int32_t height;
uint16_t planes;
uint16_t bitsPerPixel;
uint32_t compression;
uint32_t imageSize;
int32_t xPixelsPerMeter;
int32_t yPixelsPerMeter;
uint32_t colorsUsed;
uint32_t importantColors;
} BMPHeader;
#pragma pack()
int main() {
char bmpFileName[] = "image.bmp";
BMPHeader header;
fread(&header, sizeof(BMPHeader), 1, bmpFile);
fclose(bmpFile);
return 0;
}
C-Output:
Matlab Code:
info = imfinfo('image.bmp');
disp(info);
Matlab-Output: