Available in the LEADTOOLS Imaging toolkit. |
Pixel example for Visual Basic
This example, using the MouseDown event, gets the value of the current pixel and sets all values in the line to that value. The example shows how to convert mouse coordinates to bitmap pixel coordinates, regardless of how the image is zoomed or scrolled.
Private Sub Lead1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim xycolor As Long
Dim xfraction As Single
Dim yfraction As Single
Dim xPixel As Long
Dim yPixel As Long
'In VB, you get TWIPS; so set the scalemode accordingly.
Lead1.ScaleMode = 1
'Translate mouse coordinates to fractions of the destination width and height.
xfraction = (x - Lead1.DstLeft) / Lead1.DstWidth
yfraction = (y - Lead1.DstTop) / Lead1.DstHeight
'Set the scalemode to pixels and convert fractions to bitmap pixel coordinates.
Lead1.ScaleMode = 3
xPixel = (Lead1.SrcWidth * xfraction) + Lead1.SrcLeft
yPixel = (Lead1.SrcHeight * yfraction) + Lead1.SrcTop
'Make the whole line the same color as the pixel.
xycolor = Lead1.Pixel(xPixel, yPixel)
For xPixel = 0 To Lead1.BitmapWidth - 1
Lead1.Pixel(xPixel, yPixel) = xycolor
Next
Lead1.ForceRepaint
End Sub