0% found this document useful (0 votes)
10 views3 pages

Lab_3

Uploaded by

Maaz Sayyed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Lab_3

Uploaded by

Maaz Sayyed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment Number: 3

NAME: Sayyed Md Muaz Aslam ROLLNO: 60


CLASS: TY_IT_A BATCH: B3 PRN No.: 12110133

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";

FILE *bmpFile = fopen(bmpFileName, "rb");


if (!bmpFile) {
printf("Error: Could not open the BMP file.\n");
return 1;
}

BMPHeader header;
fread(&header, sizeof(BMPHeader), 1, bmpFile);

fclose(bmpFile);

printf("BMP Header Information:\n");


printf("Type: %c%c\n", header.type & 0xFF, (header.type >>
8) & 0xFF);
printf("File Size: %u bytes\n", header.fileSize);
printf("Image Offset: %u bytes\n", header.offset);
printf("Width: %d pixels\n", header.width);
printf("Height: %d pixels\n", header.height);
printf("Bits per Pixel: %d\n", header.bitsPerPixel);

return 0;
}

C-Output:

Matlab Code:

info = imfinfo('image.bmp');
disp(info);

Matlab-Output:

You might also like