Thread: How to Convert a bmp image into Array

  1. #1
    Registered User
    Join Date
    Jul 2020
    Posts
    12

    How to Convert a bmp image into Array

    I have a bitmap image(543 Χ 800) and i want to convert it into an Array of (bytes?) in order to process it in embedded system environment. Any help would be precious!

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,076
    Isn't this a matter of parsing the file according to the format?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2020
    Posts
    12
    I basically want the array of rgb values.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,076
    Okay, so what's stopping you from getting them?

    I mean, you can either find an existing library to do the parsing for you, or you can implement a parser yourself (especially if you have very specific requirements and hence don't have to worry about variations of the BMP file format).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2019
    Posts
    763
    Use GIMP and Export to C file. Example (I want to believe X-Files poster):
    Code:
    /* GIMP RGB C-Source image dump (believe.c) */
    
    static const struct {
      unsigned int   width;
      unsigned int   height;
      unsigned int   bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
      unsigned char  pixel_data[320 * 402 * 3 + 1];
    } gimp_image = {
      320, 402, 3,
      "\261\331\316\254\326\312\251\323\307\251\324\310\252\330\313\251\331\313"
      "\247\327\311\247\332\313\251\330\314\247\325\310\252\330\313\254\332\317"
      ...
    };

  6. #6
    Registered User
    Join Date
    Jul 2020
    Posts
    12
    Quote Originally Posted by flp1969 View Post
    Use GIMP and Export to C file. Example (I want to believe X-Files poster):
    Code:
    /* GIMP RGB C-Source image dump (believe.c) */
    
    static const struct {
      unsigned int   width;
      unsigned int   height;
      unsigned int   bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
      unsigned char  pixel_data[320 * 402 * 3 + 1];
    } gimp_image = {
      320, 402, 3,
      "\261\331\316\254\326\312\251\323\307\251\324\310\252\330\313\251\331\313"
      "\247\327\311\247\332\313\251\330\314\247\325\310\252\330\313\254\332\317"
      ...
    };
    I have already exported via gimp it as C source code(Do you mean this...?.How do i read the .c output now?

  7. #7
    Registered User
    Join Date
    Feb 2019
    Posts
    763
    Quote Originally Posted by stzog View Post
    I have already exported via gimp it as C source code(Do you mean this...?.How do i read the .c output now?
    I believe the listing is self explanatory.

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    3,920
    OP:

    Do you know what an Compiler is? If no, you need to learn about Compilers.
    Do you have an C Compiler for your embedded system? If no, find one.
    Do you know how to compile an C file for your embedded system? If no, find out how.

    If you still have problems post the information needed to help you; if you fail to post the information I for one will write you off as an "Help Vampire".
    The answers to the above questions is needed information!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  9. #9
    Registered User
    Join Date
    May 2012
    Posts
    452
    Quote Originally Posted by stzog View Post
    I have a bitmap image(543 Χ 800) and i want to convert it into an Array of (bytes?) in order to process it in embedded system environment. Any help would be precious!
    Go onto my website (link below) and get the Baby X resource compiler. It is designed for this job. It converts resources, mainly images, into C code.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 11-20-2013, 03:46 PM
  2. Convert video to image
    By rwcradio in forum C Programming
    Replies: 7
    Last Post: 11-20-2007, 03:36 AM
  3. how to convert a bitmap image to a jpg image file using C++?
    By nomer in forum Windows Programming
    Replies: 4
    Last Post: 06-04-2006, 07:40 PM
  4. Hi, how to convert a grayscale image into 8 bit image?
    By Alexanderbinich in forum C++ Programming
    Replies: 3
    Last Post: 03-15-2005, 07:50 PM
  5. Replies: 6
    Last Post: 03-03-2005, 03:52 AM

Tags for this Thread