Hello everyone!
I want to draw gradient segments at any angle,
Refer to this example
But drawing more times will make the following mistakes
Out of bounds. Index=? Length=?
A gradient effect like this
I want to draw gradient segments at any angle,
Refer to this example
But drawing more times will make the following mistakes
Out of bounds. Index=? Length=?
B4X:
#Region Project Attributes
#ApplicationLabel: B4i Example
#Version: 1.0.0
'Orientation possible values: Portrait, LandscapeLeft, LandscapeRight and PortraitUpsideDown
#iPhoneOrientations: Portrait, LandscapeLeft, LandscapeRight
#iPadOrientations: Portrait, LandscapeLeft, LandscapeRight, PortraitUpsideDown
#Target: iPhone, iPad
#ATSEnabled: True
#MinVersion: 8
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public App As Application
Public NavControl As NavigationController
Private Page1 As Page
'Private xui As XUI
Private ImageView1 As ImageView
End Sub
Private Sub Application_Start (Nav As NavigationController)
NavControl = Nav
Page1.Initialize("Page1")
Page1.RootPanel.LoadLayout("Page1")
NavControl.ShowPage(Page1)
End Sub
Sub Button1_Click
'xui.MsgboxAsync("Hello world!", "B4X")
Dim no As NativeObject
ImageView1.Bitmap = no.Initialize ("UIImage").RunMethod ("new", Null)
Dim Bc As BitmapCreator
Bc.Initialize(ImageView1.Width, ImageView1.Height)
Dim bc2 As BitmapCreator
Dim x As Float,y As Float
Dim x1 As Float,y1 As Float
Dim x2 As Float,y2 As Float
x=200
y=300
Dim w As Int=20
For i=1 To 100
x1=Rnd(-100,100)
y1=Rnd(-100,100)
x2=x+x1
y2=y+y1
Dim bc2 As BitmapCreator
If x1<w Then
If y1<w Then
bc2.Initialize(w,w)
Else
bc2.Initialize(w,Abs(y1))
End If
Else
If y1<w Then
bc2.Initialize(Abs(x1),w)
Else
bc2.Initialize(Abs(x1),Abs(y1))
End If
End If
bc2.FillRadialGradient(Array As Int(Colors.RGB(0,128,0),Colors.RGB(0,192,0)),bc2.TargetRect)
Bc.DrawLine2(x, y, x2, y2, Bc.CreateBrushFromBitmapCreator(bc2), w)
x=x2
y=y2
Next
'Bc.SetBitmapToImageView(Bc.Bitmap,ImageView1)
ImageView1.Bitmap=Bc.Bitmap
End Sub
Private Sub Page1_Resize(Width As Int, Height As Int)
ImageView1.SetLayoutAnimated(0,0,0,ImageView1.Top,Width,Height-ImageView1.Top)
End Sub
A gradient effect like this
Attachments
Last edited: