![]() |
|
#1
|
|||
|
|||
Help with bitmap conversion/header in CSo, here's the deal. I have a school project, part of which is being able to construct your own bitmaps, including header a all, straight through binary write to a file.
Our first assignment is to read and flatten a 512x512 24-bit Lena into a 1-dimensional char array of appropiate length, in the process converting the RGB coordinates for the colors into 8-bit grayscale. My group gets through reading the file just fine, into a format that seems fine, judging by watching the array while debugging. Then we get to writing to a new .bmp-file, and all goes to hell. Yes, it does turn into a readable bitmap format, but it looks pretty darn funky. Just take a look at the attachment. Source code is also included. But after looking at it for almost 3-4 hours, and having lab assistants try to help us, no luck. So, any of you who could possibly help? I haven't really been able to isolate the problem, but I imagine it has something to do with the header. Also, I use NetBeans as IDE, Cygwin as compiler. ![]() Thanks in advance. EDIT: Darn it, didn't know photobucket compressed the images. Anyways, you can see what the product looks like, to get a general idea of what is wrong, perhaps. If you require the original bmp to see the binary of the header, I will of course provide that. |
|||
|
#2
|
|||
|
|||
Re: Help with bitmap conversion/header in CQuote:
I don't think so. Maybe you are seeing what you expect in the debugger, but that isn't correct. (In other words, I think the program is doing exactly what you are telling it to do, but what you are telling it is incorrect.) In a 24-bit color bitmap file, there are three bytes per pixel, not four. Maybe you were confused by the fact that the color table for an 8-bit bitmap file has four bytes for each color value (three color values and a padding byte for each color). You got that part right in the bmp_save() function. Anyhow... CPP / C++ / C Code:
That might give you something better to look at. But: See Footnote. I think that it is always a good idea to make sure that file I/O operations are successful. (Test the return value of fread to make sure the read was successful. You might have discovered that it failed inside the loop since you were actually trying to read too many bytes. You could have seen that as a clue.) Regards, Dave Footnote: Note that the pixel data elements in the file are unsigned chars: 0x00 = darkest, 0xff = brightest. Last edited by davekw7x : 09-Sep-2009 at 14:46.
|
Recent GIDBlog
Problems with the Navy (Enlisted) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Convert a bitmap file to an icon file | fakepoo | .NET Forum | 1 | 19-May-2009 14:21 |
| MFC send Bitmap from callbackfct to OnDraw | PoPo93 | MS Visual C++ / MFC Forum | 0 | 17-Jan-2008 09:12 |
| Query regarding BITMAP refresh..!! | vab | MS Visual C++ / MFC Forum | 1 | 10-Jul-2006 03:58 |
| Two Dialog projects using same bitmap file | Dominic | MS Visual C++ / MFC Forum | 3 | 03-Jul-2006 08:51 |
| How to store and re-use a bitmap | Dominic | MS Visual C++ / MFC Forum | 0 | 23-Mar-2006 03:56 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The