How to create bitmaps (in C)?

I am wondering how I can import and export bitmaps from and to C. I basically lost where to start.

+3
source share
7 answers

The bitmap in memory looks something like this:

struct Image {
    int width;
    int height;
    char *data;    // 1 byte per channel & only 1 channel == grayscale
}

struct Image theImage;
theImage.width = 100;
theImage.height = 100;
theImage.data = malloc(sizeof(char) * theImage.width * theImage.height);

Regarding import and export, there are some really simple file formats, see BMP . For more complex formats, it is best for you to use an already available library.

Most frameworks already have load / save methods for the most common file formats. You can take a look at the SDL if you are looking for a lightweight library.

+2

API ImageMagick C, MagickWand? , .

+2

SDL . , , PNG SDL_image .

- GD.

+1

. , . GUI API/Framework .

+1

" " , Windows BMP.

(, gd). .

0

netpbm/pbmplus, ; API , .

This semester, I wrote a significant number of programs for beginner students to use for image processing; you can check homework and support software for the Tufts course Machine structure and assembly language programming .

0
source

Source: https://habr.com/ru/post/1725216/


All Articles