My program generates a grayscale image in binary format. I want to convert it to bitmap format (BMP) so that I can view it but I don't know how to do the conversion.
The image data is in 8 bit binary in a file with the extension .bin
I installed a program called IrfanView that can be used to view images. However, IrfanView does not support .bin files. Therefore, I am looking for a way to convert the .bin file to .bmp
You're the only one to know what format your picture is stored in. Here is a description of the bitmap layout http://en.wikipedia.org/wiki/BMP_file_format. All you have to do is to translate your format into it.
Last edited by S_M_A; January 4th, 2012 at 05:07 AM.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
The image data is in 8 bit binary in a file with the extension .bin
The file extension means nothing. What is important is for you to know the layout of this "bin" file. I can create a BMP file, put a ".bin" extension on it, and it is just as valid as what you're describing.
I installed a program called IrfanView that can be used to view images. However, IrfanView does not support .bin files.
Then you need to know exactly what ".bin" means, because that is such a generic term, no software will know what it is without inspecting the file.
The IrfranView program is made to identify files by looking at their layouts. For example, all BMP files start with "BM", TIFF files start with "II" or "MM", JPEG files have their markers, etc. Your "bin" file follows none of the major file formats in terms of identification.
Therefore, I am looking for a way to convert the .bin file to .bmp
You can't convert anything until you get a formal description of this "bin" format. Things such as how the color information is stored, pixel information, etc.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; January 3rd, 2012 at 07:56 PM.
As others have said, this "bin" file could be anything - for example, take a look here to see some examples of various file formats that all use the bin extension (just something I googled up). The thing about extensions is that they can be anything regardless of the actual file type.
So, the first thing to do is to tell us where did you get this file, and what app created it.
You also might want to take a look at this, as it seems that Picasa can open some "bin" image file format, created by some Wii games (in-game screenshots).
I modified the existing code to convert my binary grayscale image. I was abled to create a BMP file. However, the color code is not correct. I believe that I did not set the color table. If anyone knows how to set the color table for the 8-bit grayscale, please help.
I believe you pointed me to the right direction. However, I still have a problem to call the function DrawGrayScale from the "main" because I don't know what CDC and HANDLE are.
Attached is my latest code. I greatly appreciate your help if you can show me how to pass CDC and HANDLE from the main to DrawGrayScale.
... I still have a problem to call the function DrawGrayScale from the "main" because I don't know what CDC and HANDLE are.
It is because "main" was not designed to draw something from within it.
In Windows you should draw anything in the response of WM_PAINT message.
So what you need is a GUI project (Win32 or MFC) where you will handle WM_PAINT message or override OnPaint (or OnDraw in the case of MFC SDI/MDI apps) and make your drawing...
I created a GUI project via MFC. I was able to draw my data on a window. But my old (main) program has lots of signal processing code. Therefore, I cannot abandon it. Do I have to transfer all the code in main to OnDraw procedure?
I wrote a C++ program where the main reads several binary-image input files and process them. The output is an array of binary data. I want to store this data in a bitmap grayscale file and display it.
According to your instruction, I created a MFC GUI and manually enter the data. But this GUI is independent from my main program. Do I have to abandon my main and move all of the logic from main to OnDraw?
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.