Question: I can't see the binary output in output.BMP the output is just black image, please help me fix below C code to see the binary

I can't see the binary output in output.BMP the output is just black image, please help me fix below C code to see the binary output:
#include
#include
#include
// Function to read BMP file header
void readBMPHeader(FILE *file, uint32_t *width, uint32_t *height){
fseek(file,18, SEEK_SET);
fread(width, sizeof(uint32_t),1, file);
fread(height, sizeof(uint32_t),1, file);
}
// Function to convert grey level to binary
int greyToBinary(int greyLevel){
return (greyLevel =127)?0 : 1;
}
// Function to convert BMP image to binary
void convertToBinary(const char *inputFile, const char *outputFile){
FILE *input = fopen(inputFile,"rb");
FILE *output = fopen(outputFile,"wb");
if (input == NULL || output == NULL){
printf("Error: Unable to open files.
");
exit(EXIT_FAILURE);
}
uint32_t width, height;
readBMPHeader(input, &width, &height);
// Write BMP header
fseek(input,0, SEEK_SET);
fseek(output,0, SEEK_SET);
uint8_t header[54];
fread(header, sizeof(uint8_t),54, input);
fwrite(header, sizeof(uint8_t),54, output);
// Iterate through each pixel
for (int i =0; i height; i++){
for (int j =0; j width; j++){
uint8_t pixel;
fread(&pixel, sizeof(uint8_t),1, input);
int binaryPixel = greyToBinary((int)pixel);
fwrite(&binaryPixel, sizeof(uint8_t),1, output);
}
}
fclose(input);
fclose(output);
}
int main(){
const char *inputFile = "bird.bmp";
const char *outputFile = "output.bmp";
// Convert BMP image to binary
convertToBinary(inputFile, outputFile);
printf("Conversion completed successfully.
");
return 0;
}
I can't see the binary output in output.BMP the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!