C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-28-2008, 07:07 AM   #1
Registered User
 
Join Date: Jul 2008
Posts: 2
Question Bitmap in C programming

Pls tell me how can i produce a code that will write lets say a line or rectangle in a bitmap file. I understand that i need to have a header file which I already had written. What i do not understand is how can I exactly write to a binary file like a bitmap. I need explanations on how can i work out the problem. thank you.
aaron08 is offline   Reply With Quote
Old 07-28-2008, 08:22 AM   #2
Wheres the lesbians?
 
mike_g's Avatar
 
Join Date: Oct 2006
Location: UK
Posts: 1,219
use fopen to open the file. If you want to read as well as write use "r+b" as the second parameter. You can then use fseek to get where you want in the file. If you are writing multibyte data then I think you will also want to cast it to a character array before writing, and you may need to reverse it when reading IIRC.
__________________
Senior highbrow doctor of authority.
mike_g is offline   Reply With Quote
Old 07-28-2008, 08:43 AM   #3
Registered User
 
Join Date: May 2008
Posts: 53
It depends in what format the bitmap file is. Many image formats can be read/written with freely available libraries (libjpeg, libpng, libtiff); other formats are relatively simple and can be decoded and encoded "manually".

I don't understand your remark about a header file.

--
Computer Programming: An Introduction for the Scientifically Inclined
Sander is offline   Reply With Quote
Old 07-28-2008, 09:12 AM   #4
Registered User
 
Join Date: Jul 2008
Posts: 2
what i know is that each bitmap file has a file header which contains the size of the image, the bits per pixel etc.
aaron08 is offline   Reply With Quote
Old 07-28-2008, 09:21 AM   #5
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
http://en.wikipedia.org/wiki/BMP_file_format
"draw" your line in a large array of pixels, then write them out the file.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 07-28-2008, 09:21 AM   #6
Registered User
 
Join Date: Oct 2001
Posts: 2,110
a header file is source code. (stdio.h, stdlib.h, etc)

a file header is data that goes before other data in a file.
robwhit is offline   Reply With Quote
Old 07-28-2008, 03:00 PM   #7
Registered User
 
Join Date: May 2008
Posts: 53
Quote:
Originally Posted by aaron08 View Post
what i know is that each bitmap file has a file header which contains the size of the image, the bits per pixel etc.
That's what all but the most trivial bitmap file formats have. It depends on the exact file format (i.e., is it a BMP file? GIF, JPEG, TIFF, PNG?) what the precise layout of this file header is. Some file formats are relatively simple and you can read the bitmap data as a simple array of pixels, others have some form of compression and are going to be difficult to parse. Fortunately, like I said, there are often libraries available; or perhaps your OS has built-in functions to deal with these files.

--
Computer Programming: An Introduction for the Scientifically Inclined
Sander is offline   Reply With Quote
Old 07-28-2008, 04:38 PM   #8
Wheres the lesbians?
 
mike_g's Avatar
 
Join Date: Oct 2006
Location: UK
Posts: 1,219
Yeah, but GIF, JPEG, TIFF and PNG are not bitmaps. Bitmaps should have "BM" (edit: in ASCII) as the first two bytes in the header. Palleted bitmaps can complicate things tho.
__________________
Senior highbrow doctor of authority.

Last edited by mike_g; 07-28-2008 at 04:40 PM.
mike_g is offline   Reply With Quote
Old 07-29-2008, 02:00 AM   #9
Registered User
 
Join Date: May 2008
Posts: 53
That depends on what your definition of "bitmap" is. If you mean "the contents of a BMP file" then you are right. But you could also mean "a rectangular array of pixel values" (as opposed to a "vector image"). It wasn't clear to me from the original poster what he meant.
Sander is offline   Reply With Quote
Reply

Tags
bitmap, graphing

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading a bitmap (Without using glaux) Shamino Game Programming 7 03-16-2006 09:43 AM
OpenGL -- Bitmaps HQSneaker Game Programming 14 09-06-2004 04:04 PM
Loading a Bitmap resource for OpenGL Texture[x] the dead tree Game Programming 4 08-26-2004 01:12 PM
bitmap not going onto screen stallion Windows Programming 4 02-22-2003 10:07 AM
texture is all white in opengl! Crossbow Game Programming 7 03-31-2002 11:54 AM


All times are GMT -6. The time now is 06:58 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22