How To Convert Binary Image To BMP
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Thread: How To Convert Binary Image To BMP

  1. #1
    Join Date
    Jan 2012
    Posts
    6

    How To Convert Binary Image To BMP

    To C++ fans,

    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.

    Please help.

    Thanks in advance

  2. #2
    Join Date
    Apr 1999
    Posts
    27,427

    Re: How To Convert Binary Image To BMP

    Quote Originally Posted by timini View Post
    To C++ fans,

    My program generates a grayscale image in binary format.
    What do you mean by "binary format"? All image formats are "binary formats".

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jan 2012
    Posts
    6

    Re: How To Convert Binary Image To BMP

    Hi Paul,

    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

    I hope this is clear enough.

    Thanks

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,634

    Re: How To Convert Binary Image 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 04: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

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  5. #5
    Join Date
    Apr 1999
    Posts
    27,427

    Re: How To Convert Binary Image To BMP

    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 06:56 PM.

  6. #6
    Join Date
    Jan 2010
    Posts
    1,099

    Re: How To Convert Binary Image To BMP

    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).

  7. #7
    Join Date
    Jan 2012
    Posts
    6

    Re: How To Convert Binary Image To BMP

    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.

    Thanks in advance.
    Attached Files Attached Files

  8. #8
    Join Date
    Apr 1999
    Posts
    27,427

    Re: How To Convert Binary Image To BMP

    Quote Originally Posted by timini View Post
    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.
    That is because your code forgot to write the palette information.

    http://www.codeguru.com/cpp/g-m/bitm...icle.php/c1755

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Jan 2012
    Posts
    6

    Re: How To Convert Binary Image To BMP

    Hi Paul,

    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.

    Regards,

    timini
    Attached Files Attached Files

  10. #10
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,383

    Re: How To Convert Binary Image To BMP

    Quote Originally Posted by timini View Post
    ... 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...
    Victor Nijegorodov

  11. #11
    Join Date
    Jan 2012
    Posts
    6

    Re: How To Convert Binary Image To BMP

    Hi VictorN,

    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?

    Thanks in advance

    timini

  12. #12
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,383

    Re: How To Convert Binary Image To BMP

    1. What is "signal processing code"?
    2. You should move to OnDraw only the code used for drawing (or such a code could be called from the OnDraw...)
    Victor Nijegorodov

  13. #13
    Join Date
    Jan 2012
    Posts
    6

    Re: How To Convert Binary Image To BMP

    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?

    Thanks

  14. #14
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,383

    Re: How To Convert Binary Image To BMP

    I have no idea about your current program "logic" but yes: you should move your code from the console to GUI application.
    Victor Nijegorodov

  15. #15
    Join Date
    Jul 2012
    Posts
    1

    Re: How To Convert Binary Image To BMP

    Hi timini,

    could you please upload the mfcGUI application where you are able to see the o/p in window

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center