Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C++
#include "define.h"

void bmp_read(char *filename, bmp *b)
{
    FILE *input = fopen(filename, "rb");
    if(input == NULL)
    {
        return;
    }
    fread(&b->header.type, 2, 1, input);
    fread(&b->header.size, 4, 1, input);
    fread(&b->header.reserved1, 2, 1, input);
    fread(&b->header.reserved2, 2, 1, input);
    fread(&b->header.offset, 4, 1, input);

    fread(&b->info.size, 4, 1, input);
    fread(&b->info.width, 4, 1, input);
    fread(&b->info.height, 4, 1, input);
    fread(&b->info.planes, 2, 1, input);
    fread(&b->info.bits, 2, 1, input);
    fread(&b->info.compression, 4, 1, input);
    fread(&b->info.imagesize, 4, 1, input);
    fread(&b->info.xresolution, 4, 1, input);
    fread(&b->info.yresolution, 4, 1, input);
    fread(&b->info.ncolours, 4, 1, input);
    fread(&b->info.importantcolours, 4, 1, input);

    b->info.imagesize   = b->info.width * b->info.height * 3;
    b->data             = new unsigned char [b->info.imagesize];
    fread(b->data, b->info.imagesize, 1, input);

    fclose(input);
}
Posted
Updated 5-Jan-16 8:28am
v2
Comments
Richard MacCutchan 5-Jan-16 13:30pm    
Sorry, this site does not provide a code conversion service. You should look into the various file readers available in C#.

1 solution

With C# (.NET), you don't need to read a .BMP file directly. You can use System.Drawing.Bitmap methods:
Bitmap Class (System.Drawing)[^].

You can open a .BMP file, or a file of a number of different formats, with one of the constructors: Bitmap Constructor (System.Drawing)[^].

And these are save methods:
Bitmap Constructor (System.Drawing)[^],
Bitmap.SaveAdd Method (System.Drawing)[^].

That's all.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900