B4J Question Disabling anti aliasing on text

Daestrum

Expert
Licensed User
Longtime User
Are you confusing Text (the Object) with text inside the canvas?

javafx.scene.text.Text is an object that can be added anywhere in the scene graph it doesn't need a container.

what you probably want is (uses JavaObject Library)
B4X:
(Canvas1).As(JavaObject).RunMethodjo("getGraphicsContext2D",Null).RunMethod("setImageSmoothing",Array(False))
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Thanks, but this gives me

java.lang.RuntimeException: Method: getGraphicsContext2D not found in: anywheresoftware.b4a.objects.B4XCanvas
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
thats odd - working fine here with
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI 
    Private Button1 As B4XView
    Private Canvas1 As B4XView
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
    Dim txt As JavaObject
    txt.InitializeNewInstance("javafx.scene.text.Text",Array("hello"))  
    MainForm.RootPane.AddNode(txt,20,20,100,20)
    (Canvas1).As(JavaObject).RunMethodjo("getGraphicsContext2D",Null).RunMethod("setImageSmoothing",Array(False))
End Sub

Sub Button1_Click
    Canvas1.As(Canvas).DrawText("Hello",20,20,xui.CreateFont(fx.DefaultFont(20),20),fx.Colors.Blue,"LEFT")
End Sub
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
I suspect this is because I'm using
B4X:
Dim Canvas As B4XCanvas
and you're using
B4X:
Dim Canvas1 As B4XView
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Still stuck with this... it would be so much easier if you could DISABLE the anti aliasing on B4XCanvas.
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
You can get the native canvas from B4XCanvas with this (from @Erel)
And then apply the solution of @Daestrum MAYBE, I haven't tested it.

B4X:
'B4J and B4A
Sub GetNativeCanvas (b4x As B4XCanvas) As Canvas
   Dim jo As JavaObject = b4x
   jo = jo.GetFieldJO("cvs")
   If XUI.IsB4J Then Return jo.RunMethod("getObject", Null)
   Return jo
End Sub
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Just curious, why do you need disabling anti aliasing on text? I may just use a bitmap font and make a font rendering function myself.

 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You can put it in one line but the code looks horrendous :) where cv is a B4XCanvas
B4X:
(((cv).As(JavaObject).GetFieldJO("cvs")).As(B4XView)).As(JavaObject).RunMethodJO("getGraphicsContext2D",Null).RunMethod("setImageSmoothing",Array(False))
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
It's not working unfortunately, the text is still anti aliased. I've added a Wish on the forum to add this function on B4XCanvas. What I thought would be simple is sometimes SO complex in B4X...
I could switch to a bitmap font and create the font rendering myself, but that's a lot of work (and probably overkill).
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
Can you try this? found from internet.

Java:
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
 
Upvote 0
Top