Reputation: 19
I am creating a program that can read a bmp image and calculate the percentage of red, blue and green color on it. I have searched a lot but haven't understood that from which byte does the image data exactly begins and how to get the RGB values of the pixels?
#include<stdio.h>
typedef struct {
unsigned int fileSize;
unsigned int offset;
unsigned int reserved;
char signature[2];
} BmpHeader;
typedef struct {
unsigned short bitDepth;
unsigned int compressedImageSize;
unsigned int compression;
unsigned int headerSize;
unsigned int height;
unsigned int horizontalResolution;
unsigned int importantColors;
unsigned int numColors;
unsigned short planeCount;
unsigned int verticalResolution;
unsigned int width;
} BmpImageInfo;
typedef struct {
unsigned char blue;
unsigned char green;
unsigned char red;
} Rgb;
int main(void) {
BmpHeader header;
BmpImageInfo info;
char filename[40];
printf("Enter file name : ");scanf("%s", filename);
FILE *fp;
fp = fopen(filename, "rb");
fread(&header, 1, sizeof(BmpHeader), fp);
fread(&info, 1, sizeof(BmpImageInfo), fp);
printf("%u", info.height);
getchar();
return 0;
}
WHY AM I GETTING THE WRONG HEIGHT???
Upvotes: 0
Views: 1771
Reputation: 16540
This link is to the wiki page that describes the .bmp image format. Things to note:
Upvotes: 3