Android Question How to access "translate" or "scale" on Canvas using JavaObject?

LucianDesign

Member
Licensed User
Longtime User
Hello,
I want to use the "translate" or "scale" on Canvas using JavaObject but is not working ... the "drawPath" method is working. (https://developer.android.com/reference/android/graphics/Canvas.html)

Any ideas why?

This is the example code:

B4X:
'myPath and myCanvas need to exist

Dim Paint, CanvJO, FillStyle As JavaObject
CanvJO = myCanvas
CanvJO = CanvJO.GetField("canvas")

Paint.InitializeNewInstance("android.graphics.Paint",Null)
Paint.RunMethod("setAntiAlias", Array As Object(True))
Paint.RunMethod("setColor", Array As Object(Colors.Blue))
FillStyle.InitializeStatic("android.graphics.Paint.Style")
Paint.RunMethod("setStyle", Array As Object(FillStyle.RunMethod("valueOf", Array("FILL"))))
   
CanvJO.RunMethod("translate", Array As Object(10,10)) 'This is not working! Why?
CanvJO.RunMethod("scale", Array As Object(1,-1,50,50)) 'This is not working! Why?

CanvJO.RunMethod("drawPath", Array As Object(myPath,Paint)) 'This is working.
 

LucianDesign

Member
Licensed User
Longtime User
Hello. Yes I get: java.lang.RuntimeException: Method: translate not matched.

B4X:
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (editorview) Create, isFirst = true **
Error occurred on line: 313 (Design)
java.lang.RuntimeException: Method: translate not matched.
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:129)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:748)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
    at ro.etimat.app.design._rendershape(design.java:1155)
    at ro.etimat.app.design._renderdesign(design.java:581)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at ro.etimat.app.editorview.afterFirstLayout(editorview.java:102)
    at ro.etimat.app.editorview.access$000(editorview.java:17)
    at ro.etimat.app.editorview$WaitForLayout.run(editorview.java:80)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:234)
    at android.app.ActivityThread.main(ActivityThread.java:5526)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
** Activity (editorview) Resume **
** Activity (main) Resume **
 
Upvote 0
Top