creating image from pixels stored in file

This is a discussion on creating image from pixels stored in file within the Windows Programming forums, part of the Platform Specific Boards category; Hello. I am making a viewer that reads pixels from a file and displays it on the screen. The problem ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    12

    creating image from pixels stored in file

    Hello.

    I am making a viewer that reads pixels from a file and displays it on the screen.

    The problem is that I know very little about the image.

    - I know that the file is Binary.
    - I know where in the binary file the image is (I'ts a 1024 byte large package of pixels)
    - I know that the pixels are a 16 bit signed value. (that means that one pixels use 2 bytes?)

    That's all I know.

    Can anyone give me any hints on how I can retrieve this data from the file and a method to display the data?

    If not, what information do I need to know to be able to retrieve this information?

    Kristian

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I guess I would start by assuming the 16 bits were encoded as 5 bits for each red, green and blue. Since I dont know the dimensions or the start point of the picture, I would probably start with the first pixel in the bottom left corner, (as with bitmaps), and draw a reasonable number of pixels then the same number on the line above and so on until I'd drawn all the pixels, then look at what I'd got.

    If the encoding is wrong, the picture will be garbage, so try a different encoding method. If the picture has diagonal lines, then vary the pixels per line and see if they start to line up into something.

    The obvious suggestion is to find out more about the format of the file, or the file type and look it up at wotsit or somewhere.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    12

    sounds reasonable, but...

    Yes, that sounds like a good idea. But, when I read these 16 bits, what functions do I use to convert them into pixels, and which functions do I use to display them on the screen?

    I've heard some talking about API functions?

    I use Visual C++ with MFC.

    Hoping for more good tips.

    Kristian

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    I don't use MFC. What I would do is mask out the least significant 5 bits and store that in a byte, then the next 5 bits and store that in a byte, then the next and store that. Then build a COLORREF structure from these three bytes, and use the SetPixel() API routine to put it onto my windows DC. (COLORREF and SetPixel() are both describes in the help).

    If that looked wrong, then I'd start at the other end, mask of the most significant 5 bits, etc...

    If your confortable with MFC, you may see something in that rambling which gives you a steer.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 08:51 PM
  3. Loading an image in from a resource file
    By starcatcher in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 07:44 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 05:54 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21