Overview

SmoothMagnifyEffectLib creates a refined magnifying glass effect with smooth transitions between magnified and normal areas, wrapping the FireMonkey TSmoothMagnifyEffect component. Unlike basic magnification, this effect uses separate inner and outer radii to create a gradual, professional-looking transition zone.

PropertyDetails
LibrarySmoothMagnifyEffectLib
Prefixsmag_
WrapsTSmoothMagnifyEffect
Functions22
TypeVisual effect (distortion)
CategoryCountDescription
Creation / Destruction2Create and free effect
Center Position4Get/set X and Y center
Magnification2Get/set zoom level
Inner / Outer Radius4Get/set inner and outer radii
Aspect Ratio2Get/set shape aspect
Effect Control4Enabled and trigger get/set
Error Handling4Error codes and messages
🔎 Smooth Lens: The key advantage over basic MagnifyEffectLib is the dual-radius system. The InnerRadius defines the area of full magnification, and the OuterRadius defines where the effect fades to normal — creating a smooth, natural-looking lens transition with no harsh edges.

Cross-Platform Support

PlatformSupport
Windows✅ Full support
Linux✅ Full support
Android✅ Full support

Creation & Destruction

smag#(parent#)

Creates a new smooth magnify effect attached to the specified visual control.

ParameterTypeDescription
parent#PointerTarget visual control
ReturnsPointerEffect handle, or 0 on failure

smag_free(effect#)

Destroys the effect and releases associated resources.

Error Handling

FunctionSignatureDescription
smag_error()smag_error@Returns last error code (0 = none)
smag_errormsg$()smag_errormsg$@Returns last error message
smag_strerror$(code)smag_strerror$@nConverts error code to text
smag_clearerror()smag_clearerror@Clears the error state

Center Position

Sets the center point of the magnifying lens using normalized coordinates (0–1 relative to image size).

FunctionSignatureDescription
smag_centerx#(effect#, value)smag_centerx#@#nSet X center (0–1)
smag_centerx(effect#)smag_centerx@#Get X center
smag_centery#(effect#, value)smag_centery#@#nSet Y center (0–1)
smag_centery(effect#)smag_centery@#Get Y center
PositionCenterXCenterY
Top-left corner0.00.0
Image center0.50.5
Bottom-right corner1.01.0

Magnification

Controls the zoom level inside the magnifying lens. A value of 1 means no zoom.

FunctionSignatureDescription
smag_mag#(effect#, value)smag_mag#@#nSet magnification (1.0+)
smag_mag(effect#)smag_mag@#Get magnification
ValueEffect
1.0No zoom (original size)
2.02× zoom (default)
3.0–5.0Strong magnification
5.0+Very high zoom (extreme close-up)

Inner / Outer Radius

The dual-radius system is what makes this effect "smooth." The InnerRadius defines the zone of full magnification. The OuterRadius defines where the effect fades back to normal. The area between them has a smooth gradient transition.

FunctionSignatureDescription
smag_inner#(effect#, value)smag_inner#@#nSet inner radius (0–1)
smag_inner(effect#)smag_inner@#Get inner radius
smag_outer#(effect#, value)smag_outer#@#nSet outer radius (0–1)
smag_outer(effect#)smag_outer@#Get outer radius
⚠ OuterRadius must be > InnerRadius: If outer is smaller than or equal to inner, the smooth transition zone disappears and the effect may look broken. Always keep OuterRadius > InnerRadius.
ZoneDescription
Inside InnerRadiusFull magnification (constant zoom)
Between Inner and OuterSmooth gradient from full zoom to normal
Outside OuterRadiusNormal (no magnification)

Aspect Ratio

Controls the shape of the magnifying lens.

FunctionSignatureDescription
smag_aspect#(effect#, value)smag_aspect#@#nSet aspect ratio
smag_aspect(effect#)smag_aspect@#Get aspect ratio

A value of 1.0 creates a circular lens. Values greater than 1 stretch horizontally (oval), values less than 1 stretch vertically.

Effect Control

FunctionSignatureDescription
smag_enabled#(effect#, value)smag_enabled#@#nEnable (1) or disable (0)
smag_enabled(effect#)smag_enabled@#Gets enabled state
smag_trigger#(effect#, trigger$)smag_trigger#@#$Sets trigger string
smag_trigger$(effect#)smag_trigger$@#Gets trigger string

Complete Examples

Example 1: Basic Smooth Magnify

╯ smooth-magnify.bas
let frm# = Pointer#(0)
let img# = Pointer#(0)
let eff# = Pointer#(0)

frm# = form#("Smooth Magnify Demo", 400, 350)

img# = image#(frm#)
image_bounds#(img#, 100, 30, 200, 150)
image_load#(img#, "https://picsum.photos/200/150")

' Apply smooth magnification
eff# = smag#(img#)
smag_mag#(eff#, 3)
smag_inner#(eff#, 0.2)
smag_outer#(eff#, 0.5)

form_show(frm#)

Example 2: Adjustable Controls

╯ smag-controls.bas
let frm# = Pointer#(0)
let img# = Pointer#(0)
let eff# = Pointer#(0)
let trkMag# = Pointer#(0)
let trkInner# = Pointer#(0)
let trkOuter# = Pointer#(0)
let lblMag# = Pointer#(0)
let lblInner# = Pointer#(0)
let lblOuter# = Pointer#(0)

frm# = form#("Smooth Magnify Control", 500, 520)

img# = image#(frm#)
image_bounds#(img#, 150, 20, 200, 150)
image_load#(img#, "https://picsum.photos/200/150")

eff# = smag#(img#)
smag_mag#(eff#, 3)
smag_inner#(eff#, 0.2)
smag_outer#(eff#, 0.5)

' Magnification slider (1 to 10)
lblMag# = label#(frm#, "Magnification: 3.0", 30, 190)
trkMag# = trackbar#(frm#)
trackbar_bounds#(trkMag#, 30, 215, 440, 25)
trackbar_max#(trkMag#, 100)
trackbar_value#(trkMag#, 20)
trackbar_onchange#(trkMag#, "OnMagnification")

' Inner radius slider
lblInner# = label#(frm#, "Inner Radius: 0.20", 30, 260)
trkInner# = trackbar#(frm#)
trackbar_bounds#(trkInner#, 30, 285, 440, 25)
trackbar_max#(trkInner#, 100)
trackbar_value#(trkInner#, 20)
trackbar_onchange#(trkInner#, "OnInner")

' Outer radius slider
lblOuter# = label#(frm#, "Outer Radius: 0.50", 30, 330)
trkOuter# = trackbar#(frm#)
trackbar_bounds#(trkOuter#, 30, 355, 440, 25)
trackbar_max#(trkOuter#, 100)
trackbar_value#(trkOuter#, 50)
trackbar_onchange#(trkOuter#, "OnOuter")

form_show(frm#)

function OnMagnification(sender#) local m
  let m = 1 + trackbar_value(trkMag#) / 10
  smag_mag#(eff#, m)
  label_text#(lblMag#, "Magnification: " + stri$(m, 1))
endfunction

function OnInner(sender#) local i
  let i = trackbar_value(trkInner#) / 100
  smag_inner#(eff#, i)
  label_text#(lblInner#, "Inner Radius: " + stri$(i, 2))
endfunction

function OnOuter(sender#) local o
  let o = trackbar_value(trkOuter#) / 100
  smag_outer#(eff#, o)
  label_text#(lblOuter#, "Outer Radius: " + stri$(o, 2))
endfunction

Best Practices

PracticeWhy
Always keep OuterRadius > InnerRadiusRequired for the smooth transition zone to work
Use InnerRadius 0.05–0.2 for natural lookSmall inner zone with larger outer gives realistic lens effect
Difference of 0.1–0.3 between radiiNarrow gap = sharper edge; wide gap = smoother falloff
Magnification 2–4 for practical useHigher values can cause pixelation
Prefer this over MagnifyEffectLibSmoother edges look more professional

Quick Reference

FunctionSignatureDescription
CREATION & DESTRUCTION
smag#(parent#)smag#@#Create effect
smag_free(effect#)smag_free@#Destroy effect
CENTER POSITION
smag_centerx#(effect#, value)smag_centerx#@#nSet X center (0–1)
smag_centerx(effect#)smag_centerx@#Get X center
smag_centery#(effect#, value)smag_centery#@#nSet Y center (0–1)
smag_centery(effect#)smag_centery@#Get Y center
MAGNIFICATION
smag_mag#(effect#, value)smag_mag#@#nSet zoom level
smag_mag(effect#)smag_mag@#Get zoom level
INNER / OUTER RADIUS
smag_inner#(effect#, value)smag_inner#@#nSet inner radius
smag_inner(effect#)smag_inner@#Get inner radius
smag_outer#(effect#, value)smag_outer#@#nSet outer radius
smag_outer(effect#)smag_outer@#Get outer radius
ASPECT RATIO
smag_aspect#(effect#, value)smag_aspect#@#nSet aspect ratio
smag_aspect(effect#)smag_aspect@#Get aspect ratio
EFFECT CONTROL
smag_enabled#(effect#, value)smag_enabled#@#nEnable/disable
smag_enabled(effect#)smag_enabled@#Get enabled state
smag_trigger#(effect#, trigger$)smag_trigger#@#$Set trigger
smag_trigger$(effect#)smag_trigger$@#Get trigger
ERROR HANDLING
smag_error()smag_error@Last error code
smag_errormsg$()smag_errormsg$@Last error message
smag_strerror$(code)smag_strerror$@nCode to text
smag_clearerror()smag_clearerror@Clear error state

See Also

LibraryDescription
MagnifyEffectLibBasic magnification (single radius)
PinchEffectLibPinch/bulge distortion
RippleEffectLibWater ripple distortion