B4J Tutorial Magnifying glass example

SS-2013-11-24_15.10.06.jpg


A Canvas node is used to magnify a small window under the mouse cursor.

The main code is:
B4X:
Sub iv_MouseMoved (EventData As MouseEvent)
   For x = EventData.x - box To EventData.x + box
     For y = EventData.y - box To EventData.y + box
       Dim clr As Paint
       If x > 0 AND y > 0 AND x < ivImage.Width AND y < ivImage.Height Then
         Dim pixelColor As Int = ivImage.GetPixel(x, y)
         clr = fx.Colors.From32Bit(pixelColor)
       Else
         clr = fx.Colors.White 'out of bounds
       End If
       cvs.DrawRect((x + box - EventData.x) * scale, (y + box - EventData.y) * scale, _
         scale, scale, clr, True, 0)
     Next
   Next
   cvs.DrawRect(0, 0, cvs.Width, cvs.Height, fx.Colors.Black, False, 5)
End Sub
 

Attachments

  • MagnifyingGlass.zip
    99.5 KB · Views: 867
Last edited:
Top