how to use 8 bit values (black and white picture) to create a BMP picture

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paruntha
    New Member
    • Apr 2007
    • 7

    how to use 8 bit values (black and white picture) to create a BMP picture

    Hi,

    I am using Visual Basics 2005 and I am reading 8 bit values (pixel) from a CMOS camera (385 * 288 pixels) throught a serial port and need help in creating an image out of these values in BMP format

    Thank You

    Pradeepan Arunthavarajah
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by paruntha
    I am using Visual Basics 2005 and I am reading 8 bit values (pixel) from a CMOS camera (385 * 288 pixels) throught a serial port and need help in creating an image out of these values in BMP format
    Are these grayscale values?

    Comment

    • paruntha
      New Member
      • Apr 2007
      • 7

      #3
      Originally posted by Killer42
      Are these grayscale values?
      yes these are grayscale values (8 bit) your help will be appreciated

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        Originally posted by paruntha
        yes these are grayscale values (8 bit) your help will be appreciated
        I certainly won't claim this is the best way, but perhaps the simplest would be to create a picturebox, then just loop through the values and use Pset (or whatever the equivalent is in VB.Net) to draw each pixel. Then save the picture from the picturebox.

        In VB6, I would use something like this to set the colour of each point.
        Code:
        ' Assumed values...
        ' X = X coordinate
        ' Y = Y coordinate
        ' InputvALUE = grayscale value from white (0) to black (255)
        InputColour = 255 - InputValue
        OutputColour = RGB(InputColour, InputColour, InputColour)
        Picture1.Pset (X, Y), OutputColour

        Comment

        • paruntha
          New Member
          • Apr 2007
          • 7

          #5
          thanks for ur help

          however i'm getting the values from the com port and since it's coming thru the port one character (byte) at a time how do I convert it to ASCII meaning getting the DEC (decimal) values instead of the character values. Using these decimal values which represents 8 bits (0-255) each will be used to create a picture.

          Also, I need clarifying in what Picture1.Pset command is because I will just need the picture to be displayed in PictureBox and saved as an image in BMP format

          thanks in advance

          Comment

          • Killer42
            Recognized Expert Expert
            • Oct 2006
            • 8429

            #6
            Originally posted by paruntha
            thanks for ur help

            however i'm getting the values from the com port and since it's coming thru the port one character (byte) at a time how do I convert it to ASCII meaning getting the DEC (decimal) values instead of the character values. Using these decimal values which represents 8 bits (0-255) each will be used to create a picture.
            :confused:

            What you are getting through the port will be a stream of bytes. In other words, numeric values in the range 0-255. These numbers can represent anything you want them to - you can treat them as an ASCII character, a grayscale value, or whatever.

            There are a number of functions in VB6 to convert between different formats such as ASC(string character to ASCII value) or CHR(ASCII value to string character), HEX(decimal to hexadecimal), VAL(string of numeric digits to numeric value) and so on.

            If each value represents a "picture" then it seems as though one of the following must be true...
            1. You're not making yourself clear (at least to me).
            2. They are very simple pictures, if they can be represented by a single byte.
            3. They are simply a kind of index number indicating a selection from a collection of pictures that you already have available.


            Originally posted by paruntha
            Also, I need clarifying in what Picture1.Pset command is because I will just need the picture to be displayed in PictureBox and saved as an image in BMP format
            The PSET method of the picturebox sets the specified point to the specified colour. In other words, it draws a dot. I was using it to take each grayscale value and draw a dot of the corresponding shade of gray. If this worked as planned, eventually you would drawn your image, one dot at a time. This is basically what a bitmap is - a bunch of numbers representing the colour (and/or brightness) of each dot in an image.

            Comment

            • paruntha
              New Member
              • Apr 2007
              • 7

              #7
              Originally posted by Killer42
              :confused:

              What you are getting through the port will be a stream of bytes. In other words, numeric values in the range 0-255. These numbers can represent anything you want them to - you can treat them as an ASCII character, a grayscale value, or whatever.

              There are a number of functions in VB6 to convert between different formats such as ASC(string character to ASCII value) or CHR(ASCII value to string character), HEX(decimal to hexadecimal), VAL(string of numeric digits to numeric value) and so on.

              If each value represents a "picture" then it seems as though one of the following must be true...
              1. You're not making yourself clear (at least to me).
              2. They are very simple pictures, if they can be represented by a single byte.
              3. They are simply a kind of index number indicating a selection from a collection of pictures that you already have available.


              The PSET method of the picturebox sets the specified point to the specified colour. In other words, it draws a dot. I was using it to take each grayscale value and draw a dot of the corresponding shade of gray. If this worked as planned, eventually you would drawn your image, one dot at a time. This is basically what a bitmap is - a bunch of numbers representing the colour (and/or brightness) of each dot in an image.
              yes it will be stream of bytes and each byte will represent a pixel value
              and what is PSet equivalence in visual Basic 2005
              thanks in advance

              Comment

              • Killer42
                Recognized Expert Expert
                • Oct 2006
                • 8429

                #8
                Originally posted by paruntha
                yes it will be stream of bytes and each byte will represent a pixel value and what is PSet equivalence in visual Basic 2005
                I don't know. You'll just have to look up the documentation, I suppose.

                If you can't find the equivalent command, try searching for Pset. If it's obsolete, the information about upgrading should tell you what replaced it.

                Comment

                Working...