B4J Tutorial Magnifying glass example

Erel

Administrator
Staff member
Licensed User


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

Last edited:
Top