Thread: pixels reader

  1. #1
    * Death to Visual Basic * Devil Panther's Avatar
    Join Date
    Aug 2001

    Question pixels reader

    i'm looking for a C function, that will read pixel by pixel a bmp file, and print it on the screen. thanks for the help.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Yes, it would be nice if there was such a function, but there is not.

    If you are using BGI (graphics.h) or your own VGA functions you need to do the following:

    This is not an exhaustive list nor is it in any particular order, but it gives the general idea.
    • Find out the header structure for a BMP file - data, palette data, raw data, etc (info all over the net and this board about BMP)
    • Use the C file i/o functions to read in the file header, palette data, and raw data (you will understand this if you look at the structure of a BMP).
    • Store the palette data correctly (for info on what I mean by this - go to and look at the section on loading/displaying BMPs.
    • Get a display driver for BGI that does 320x200x256 - or better yet, go to aforementioned site and learn how to program the VGA thus eliminating the need for a driver. For BMPs you only need to know how to plot a pixel in mode 13h or 320x200x256
    • Read up on palette manipulation and how to do it - you must set the palette to look exactly as it did when the artist drew the BMP or else you will get strange colors since the color you are using does not have the same RGB as it did when the picture was drawn (more info at the web site mentioned above) - The palette data in the file is what the palette looked like when the image was created)
    • Place the raw data from the file (for 256 color these will be numbers that represent which RGB's you want to use - painting by the numbers)onto the screen by plotting pixels - either with BGI function putpixel() or with your own VGA plot pixel function - whichever way you choose to go.

    It sounds confusing, but after you go to that website it should all become quite clear. This is a simple task and it will help you learn more about C in the process. Also, it is nice to actually code a program that 'does' something on screen that you can see. If you have any questions, post them here.

    I do have source for this as do many of the members of this board, but I'm not going to post it yet as that would not help you and may just confuse you more. Do some research at that site and at the ones listed in the links section of this board. They explain the whole concept very well and you'll learn more if you code it yourself.

    I tried to be very clear and helpful but perhaps I've just confused you. That site, I cannot stress enough, will help you considerably.

  3. #3
    You know, that is the _really neat thing_ about C. You can write your _own_ functions!!!!!! Yesssss!

    Try writing your own LoadBMP() function.

    Just surf the web for the BMP file format-- it's a well known Microsoft format, and implement it.

  4. #4
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001

    check the file format, get the right data at the right time in the right place... and have at it...

    hehe, you rock sayeh!
    hasafraggin shizigishin oppashigger...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Manipulating single LCD pixels
    By finnepower in forum Networking/Device Communication
    Replies: 3
    Last Post: 02-22-2008, 08:45 PM
  2. Trying to write individual pixels to the screen
    By IanC in forum C++ Programming
    Replies: 3
    Last Post: 04-14-2004, 12:49 PM
  3. bitmap pixels???????????
    By SuperNewbie in forum Windows Programming
    Replies: 2
    Last Post: 03-23-2004, 01:53 AM
  4. creating image from pixels stored in file
    By Kristian25 in forum Windows Programming
    Replies: 3
    Last Post: 01-21-2003, 02:08 PM
  5. Algo needed for 'Fit to page'
    By Unregged in forum Windows Programming
    Replies: 6
    Last Post: 10-03-2002, 07:09 AM