Android Question B4XCanvas "setAntiAlias" method

yiankos1

Active Member
Licensed User
Hello my friend,
How can i set antialias at b4x canvas?

B4X:
Dim Obj1 As Reflector
   Dim Canv As Canvas
   Canv.Initialize(Btn1) ' initialize on what you want
   Obj1.Target = Canv
   Obj1.Target = Obj1.GetField("paint")
   Obj1.RunMethod2("setAntiAlias", True, "java.lang.boolean")
This field(paint) does not exists.
 

Peter Simpson

Expert
Licensed User
Hello try this, hopefully it will do the trick for you.

B4X:
Sub CanvasRoutineSub
'Draw canvas sub
     Dim CanvasMain As Canvas
         CanvasMain.Initialize(Activity)
     SetAntiAlias(CanvasMain)

     'Put the rest of your canvas code here
End Sub

'Set Anti Alias
Sub SetAntiAlias (Canvas1 As Canvas)
     Dim Ref As Reflector
         Ref.Target = Canvas1

     Dim NativeCanvas As Object = Ref.GetField("canvas")
     Dim PaintFlagsDrawFilter As Object = Ref.CreateObject2("android.graphics.PaintFlagsDrawFilter", Array As Object(0, 1), Array As String("java.lang.int", "java.lang.int"))

     Ref.Target = NativeCanvas
     Ref.RunMethod4("setDrawFilter", Array As Object(PaintFlagsDrawFilter), Array As String("android.graphics.DrawFilter"))
End Sub
Enjoy...
 
Last edited:
Top