Working with Bitmap in C
Hi all, currently I am working on writing a program in C language that can modify images. I have a general idea how things gonna work but I have no idea how to work with the bytes of the bitmap file. Can anyone give a clue how to modify the bytes or display them using langauge C?
thanks = )
First you need to do is to read about the structure of bitmap file format, you can get information about it here http://www.wotsit.org/ . Once you''ve read about that you''ll need to create a structure of the header file that gives you information about the image of a particular file so you can read it in correctly. To read in bytes you can use unsigned char arrays that would be easiest to use for manipulating the image. To display them you''ll need to choose a graphics lib suchs as direct draw or opengl or something else you''ll have to decide on it. Also with microsoft bitmap files, if you create your own bitmap header structure you''ll need to tell the compiler to pack the structure in memory to read the header correctly which depends on what compiler you use, if you use VC then you can tell it to pack the struct like this
"#pack(1) struct/class header { ... }; #pack()"
on the gcc compilers you tell it to pack like this:
"struct/class header { ... }__attribute__((packed));"
"#pack(1) struct/class header { ... }; #pack()"
on the gcc compilers you tell it to pack like this:
"struct/class header { ... }__attribute__((packed));"
If you''re working on Windows, take advantage of the Win32 API and use the BITMAPINFOHEADER and related data structures.
For display, keep in mind that Windows'' Device Independent Bitmaps (DIBs) are the same thing as BMPs, except that they may be vertically inverted. Thus, it is trivial to display BMPs/DIBs in Windows. Here''s the MSDN Bitmap Functions reference.
Assuming you don''t want to tie your code to Windows, still consider using middleware like SDL, DevIL and so forth. These libraries encapsulate functionality for loading, manipulating and displaying images (DevIL more manipulation than SDL; SDL more display than DevIL) and will allow you to focus on the parts that make your application unique rather than on "boilerplate" code.
For display, keep in mind that Windows'' Device Independent Bitmaps (DIBs) are the same thing as BMPs, except that they may be vertically inverted. Thus, it is trivial to display BMPs/DIBs in Windows. Here''s the MSDN Bitmap Functions reference.
Assuming you don''t want to tie your code to Windows, still consider using middleware like SDL, DevIL and so forth. These libraries encapsulate functionality for loading, manipulating and displaying images (DevIL more manipulation than SDL; SDL more display than DevIL) and will allow you to focus on the parts that make your application unique rather than on "boilerplate" code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement