![]() |
| | #1 |
| Registered User Join Date: May 2008
Posts: 17
| BMP file header Can i know how to read in a bmp header using C which is needed to create a new BMP image. Do i need to define a new structure for the header? Or just write a function to read it in? |
| YongzZ is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Either will work - depends on what you want to do. Note also that some of the alignment normally provided by the compiler doesn't match what the actual header in the file has, so you need to do some special trickery one way or another. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Registered User Join Date: May 2008
Posts: 17
| Thanks for the tip. I decided to read them in by using the fopen function to open the bmp header. Then use for loops to assign each pixel in the header to my BMP image. Still working on it. Is there a problem with this approach? |
| YongzZ is offline | |
| | #4 |
| Guest Join Date: Aug 2001
Posts: 4,923
| No, that sounds fine. |
| Sebastiani is offline | |
| | #5 |
| +++ OK NO CARRIER Join Date: Oct 2001
Posts: 10,258
| Jump over to Wotsit.org and look up the file format for .BMP. It should give you all you need to know. Quzah.
__________________ Hundreds of thousands of dipshits can't be wrong. Are you up for the suck? |
| quzah is offline | |
| | #6 |
| Registered User Join Date: May 2008
Posts: 17
| Thanks people. |
| YongzZ is offline | |
| | #7 |
| Registered User Join Date: May 2008
Posts: 17
| After reading them, what is the next step? Im aware i hv to write the raw data. The raw data are the colours, the pixels etc. Am i right? |
| YongzZ is offline | |
| | #8 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| What did you intend to do with it? If all you are doing is copying the file, you do not need to use a structure or understand the header -- just fread the file into an unsigned char array. You can fwrite the same buffer to (eg) "picture.bmp" and it will be identical to the original.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #9 |
| Registered User Join Date: May 2008
Posts: 17
| Im not copying, I am trying to create a bitmap file from a bmp header. And a bmp file should contain the header data, colours, and sizes, shouldn't it? |
| YongzZ is offline | |
| | #10 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| In your Original Post you say "read in"; where is that header from? Or do you really mean you want to create the header properly?
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #11 |
| Registered User Join Date: May 2008
Posts: 17
| The header is provided, i need to use it to create a BMP file by reading it in. The header if im not mistaken is part of the data in creating the BMP image. Sorry if it isn't clear. I just want to know whether im on the right track. After reading the header which is provided, my next step would be going on to write the other data for the BMP file such as colours, size, etc. Correct? |
| YongzZ is offline | |
| | #12 | |
| Registered User Join Date: Sep 2006
Posts: 2,502
| Quote:
| |
| Adak is offline | |
| | #13 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,944
| The header is part of the file. I just found this description: BMP (Windows) Header Format So the header is the first 54 bytes. The image data begins immediately after the header.
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #14 |
| Super Moderator Join Date: Aug 2001
Posts: 7,470
| You must understand the data in the header to correctly read in the file. However there are Windows functions to do this and I'm assuming you are on Windows since BMPs are decidedly a Microsoft file format. If I remember correctly each line in a BMP is byte padded to the nearest 4 byte boundary and they are stored bottom right to top left. The RGB's are also in reverse order (BGR). The size of the header, image width, image height, and image byte size are all in the header. You will need these to display the BMP correctly.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #15 |
| Registered User Join Date: May 2008
Posts: 17
| Yes, I already defined the size, width, depth etc. for the image in my BMPimage structure. So I am now going to write another function (my first one was reading the header in) to write colours. Since I already defined the size, depth, width, etc., do I need a function to write those now? Or can I now go and write in the colours? Lastly, thanks for the replies. |
| YongzZ is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Newbie homework help | fossage | C Programming | 3 | 04-30-2009 04:27 PM |
| Formatting the contents of a text file | dagorsul | C++ Programming | 2 | 04-29-2008 12:36 PM |
| Problem reading BMP | Mortissus | C Programming | 4 | 02-02-2006 06:32 AM |
| Unknown Memory Leak in Init() Function | CodeHacker | Windows Programming | 3 | 07-09-2004 09:54 AM |
| Include a header file, but where does the header file look in? | Nutshell | C Programming | 6 | 04-02-2002 05:46 AM |