Sub Process_Globals
Private fx As JFX
Private MainForm As Form
Private xui As XUI
Private Button1 As B4XView
Private Pane1 As B4XView
Private cnv As B4XCanvas
Private vpW, vpH As Float
End Sub
Sub AppStart (Form1 As Form, Args() As String)
MainForm = Form1
MainForm.RootPane.LoadLayout("Layout1")
MainForm.Show
vpW = Pane1.Width
vpH = Pane1.Height
cnv.Initialize(Pane1)
createDrawing
End Sub
Private Sub createDrawing
cnv.ClearRect(cnv.TargetRect)
cnv.DrawText("Simple Text",Rnd(vpW*0.1,vpW*0.9),vpH*0.1,xui.CreateDefaultBoldFont(16),xui.Color_Red,"CENTER")
cnv.DrawTextRotated("This is a rotated Text",Rnd(vpW*0.1,vpW*0.9),vpH*0.2,xui.CreateDefaultFont(18),xui.Color_Green,"CENTER",Rnd(0,359))
cnv.DrawRect(getRect(vpW*0.4,vpH*0.3,vpW*0.2,vpH*0.2),xui.Color_Blue,True,0)
cnv.DrawCircle(Rnd(vpW*0.1,vpW*0.9),vpH*0.6,Rnd(20,40),xui.Color_ARGB(Rnd(150,255),Rnd(0,255),Rnd(0,255),Rnd(0,255)),True,1)
Dim p As B4XPath
p.Initialize(vpW*0.3,vpH*0.7)
p.LineTo(vpW*0.6,vpH*0.85)
p.LineTo(vpW*0.45,vpH*0.9)
p.LineTo(vpW*0.25,vpH*0.8)
p.LineTo(vpW*0.3,vpH*0.7)
cnv.DrawPathRotated(p,xui.Color_Yellow,True,2,Rnd(0,359),vpW/2,vpH*0.8)
cnv.Invalidate
End Sub
Private Sub getRect(x As Float, y As Float, w As Float, h As Float) As B4XRect
Dim r As B4XRect
r.Initialize(x,y,x+w,y+h)
Return r
End Sub
Sub Button1_Click
Dim bmp As B4XBitmap = cnv.CreateBitmap.Rotate(0) 'added possibility to rotate the bitmap (you can choose between 0/90/180/270
Dim out As OutputStream
out = File.OpenOutput(File.DirApp, "Test.png", False)
bmp.WriteToStream(out, 100, "PNG")
out.Close
xui.MsgboxAsync("File saved successfully!","It Worked")
End Sub
Private Sub Button2_Click
createDrawing
End Sub