View Full Version : DrawrectangleRGB24

December 21, 2004, 03:32:32
I would like to draw a rectangle in an image similar to the DrawRectangleY8 method described in the Advances Image Processing example. The only exception is that I need to use an RGB24 image. I have tried to extrapolate the Y8 method to account for the 3 bytes per pixel, but I am unable to draw the rectangle in a single color.

Stefan Geissler
December 21, 2004, 09:22:08

First of all, you must multiply all width coordinates with 3 if you use RGB 24.

The color format is BGR, that means blue is in the first byte, green in the second and red in the third byte. To draw a yellow pixel, you must set x+1 = 255 x+2=255, where x = the pixel coordinate.

A sample for mouse movement:

Private Sub IcImagingControl1_MouseMove(ByVal sender As Object, ByVal e As TIS.Imaging.ICImagingControl.MouseEventArgs) Handles IcImagingControl1.MouseMove
If Not UserROICommited And (e.Button = MouseButtons.Left) Then
UserROI.Right = e.x * 3
UserROI.Bottom = IcImagingControl1.Height - e.y
End If
End Sub

See the “* 3” at UserROIRight.

After you have the correct mouse coordinates in, you draw the yellow rectangle as follows:

Private Sub DrawRectangleY8(ByVal Buf As TIS.Imaging.ImageBuffer, ByVal Region As RECT)
Const RECT_COLOR As Integer = 255

Dim x, y As Integer

For x = Region.Left To Region.Right Step 3
Buf(x + 1, Region.Top) = RECT_COLOR
Buf(x + 2, Region.Top) = RECT_COLOR
Buf(x + 1, Region.Bottom) = RECT_COLOR
Buf(x + 2, Region.Bottom) = RECT_COLOR
Next x
For y = Region.Top To Region.Bottom
Buf(Region.Left + 1, y) = RECT_COLOR
Buf(Region.Left + 2, y) = RECT_COLOR
Buf(Region.Right + 1, y) = RECT_COLOR
Buf(Region.Right + 2, y) = RECT_COLOR
Next y
End Sub

If you would set only Buf(Region.Left 1, y) , you would get a blue retangle.