Available in the LEADTOOLS Imaging toolkit. |
PixelData 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 Variant
Dim xfraction As Single
Dim yfraction As Single
Dim xPixel As Long
Dim yPixel As Long
'In VB, you get TWIPS; so set the scale mode 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 scale mode 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.PixelData(xPixel, yPixel)
'disable repainting
Lead1.AutoRepaint = False
For xPixel = 0 To Lead1.BitmapWidth - 1
Lead1.PixelData(xPixel, yPixel) = xycolor
Next
' re-enable repainting
Lead1.AutoRepaint = True
End Sub