iOS Question Add Glow effect to a view

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone I would like to know if there is a way to add a glow effect to a view (I'm not an expert in fact of effects).
In particular I'm using this class to display a circular loading bar, it would be cool to add a glow on the ring. You think it's possibile?

I attach an example image (don't focus on the numbers etc... only on the glow effect)

futuristic-loading-circle-ring-transfer-download-animation-122059806.jpg


Thanks!
 

Star-Dust

Expert
Licensed User
Longtime User
I think it can be done. For the moment I'm busy and I can't give you an example.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
what you could do is drawing with canvas circles with a different alpha value. something like this:

glow1.jpg


code for this:

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private cnv As B4XCanvas
    Private xui As XUI
    Private vpW, vpH As Float
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
    
    vpW = MainForm.RootPane.Width
    vpH = MainForm.RootPane.Height
    
    cnv.Initialize(MainForm.RootPane)
    cnv.DrawRect(cnv.TargetRect,xui.Color_Black,True,0)
    drawgloweffect
End Sub

Sub drawgloweffect
    cnv.DrawCircle(vpW/2,vpH/2,vpW*0.3,xui.Color_Cyan,False,vpW*0.02)
    Dim lines As Int = 10
    Dim alphastep As Int = 100/lines
    For i = 1 To lines
        Dim newcolor() As Int = GetARGB(xui.Color_Cyan,Max(0,100-(i*alphastep)))
        cnv.DrawCircle(vpW/2,vpH/2,(vpW*0.3)+(vpW*(i/300)),xui.Color_ARGB(newcolor(0),newcolor(1),newcolor(2),newcolor(3)),False,vpW*0.0055)
        cnv.DrawCircle(vpW/2,vpH/2,(vpW*0.3)-(vpW*(i/300)),xui.Color_ARGB(newcolor(0),newcolor(1),newcolor(2),newcolor(3)),False,vpW*0.0055)
    Next
End Sub

Sub GetARGB(Color As Int, alphaint As Int) As Int()
    Private res(4) As Int
    res(0) = alphaint 'Bit.UnsignedShiftRight(Bit.And(Color, 0xff000000), 24)
    res(1) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff0000), 16)
    res(2) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff00), 8)
    res(3) = Bit.And(Color, 0xff)
    Return res
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
what you could do is drawing with canvas circles with a different alpha value. something like this:

View attachment 87959

code for this:

B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private cnv As B4XCanvas
    Private xui As XUI
    Private vpW, vpH As Float
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
   
    vpW = MainForm.RootPane.Width
    vpH = MainForm.RootPane.Height
   
    cnv.Initialize(MainForm.RootPane)
    cnv.DrawRect(cnv.TargetRect,xui.Color_Black,True,0)
    drawgloweffect
End Sub

Sub drawgloweffect
    cnv.DrawCircle(vpW/2,vpH/2,vpW*0.3,xui.Color_Cyan,False,vpW*0.02)
    Dim lines As Int = 10
    Dim alphastep As Int = 100/lines
    For i = 1 To lines
        Dim newcolor() As Int = GetARGB(xui.Color_Cyan,Max(0,100-(i*alphastep)))
        cnv.DrawCircle(vpW/2,vpH/2,(vpW*0.3)+(vpW*(i/300)),xui.Color_ARGB(newcolor(0),newcolor(1),newcolor(2),newcolor(3)),False,vpW*0.0055)
        cnv.DrawCircle(vpW/2,vpH/2,(vpW*0.3)-(vpW*(i/300)),xui.Color_ARGB(newcolor(0),newcolor(1),newcolor(2),newcolor(3)),False,vpW*0.0055)
    Next
End Sub

Sub GetARGB(Color As Int, alphaint As Int) As Int()
    Private res(4) As Int
    res(0) = alphaint 'Bit.UnsignedShiftRight(Bit.And(Color, 0xff000000), 24)
    res(1) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff0000), 16)
    res(2) = Bit.UnsignedShiftRight(Bit.And(Color, 0xff00), 8)
    res(3) = Bit.And(Color, 0xff)
    Return res
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
very interesting!! thank you very much. The effect in the photo is what I would like to achieve. Now I had to understand it , and combine with the CircualrProgressBar.

Thanks again!!
 
Upvote 0
Top