By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,824 Members | 2,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,824 IT Pros & Developers. It's quick & easy.

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

P: 7
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
Apr 9 '07 #1
Share this Question
Share on Google+
7 Replies


Expert 5K+
P: 8,434
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?
Apr 10 '07 #2

P: 7
Are these grayscale values?
yes these are grayscale values (8 bit) your help will be appreciated
Apr 12 '07 #3

Expert 5K+
P: 8,434
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.
Expand|Select|Wrap|Line Numbers
  1. ' Assumed values...
  2. ' X = X coordinate
  3. ' Y = Y coordinate
  4. ' InputvALUE = grayscale value from white (0) to black (255)
  5. InputColour = 255 - InputValue
  6. OutputColour = RGB(InputColour, InputColour, InputColour)
  7. Picture1.Pset (X, Y), OutputColour
Apr 13 '07 #4

P: 7
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
Apr 23 '07 #5

Expert 5K+
P: 8,434
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.

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.
Apr 24 '07 #6

P: 7
: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
Apr 25 '07 #7

Expert 5K+
P: 8,434
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.
Apr 25 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.