Hi,
Wanted to convert RGB to CMYK values.
Trying to use the following Java code, in #If Java statement.
Calling the Java Inline code like this:
The variable "cmyk" is declared thus.
This is the asJO function.
Keep getting errors.
What am I doing wrong here?
Regards.
Wanted to convert RGB to CMYK values.
Trying to use the following Java code, in #If Java statement.
Java:
#If Java
import java.util.Arrays;
public class RgbCmykConverter {
//static
public void main(String[] args) {
int[] cmyk = rgbToCmyk(
Integer.parseInt(args[0]),
Integer.parseInt(args[1]),
Integer.parseInt(args[2])
);
System.out.println(Arrays.toString(cmyk));
}
//static
private int[] rgbToCmyk(int r, int g, int b) {
double percentageR = r / 255.0 * 100;
double percentageG = g / 255.0 * 100;
double percentageB = b / 255.0 * 100;
double k = 100 - Math.max(Math.max(percentageR, percentageG), percentageB);
if (k == 100) {
return new int[]{ 0, 0, 0, 100 };
}
int c = (int)((100 - percentageR - k) / (100 - k) * 100);
int m = (int)((100 - percentageG - k) / (100 - k) * 100);
int y = (int)((100 - percentageB - k) / (100 - k) * 100);
return new int[]{ c, m, y, (int)k };
}
}
#End If
Calling the Java Inline code like this:
B4X:
cmyk = asJO(Me).RunMethod("RgbCmykConverter", Array(argb(1), argb(2), argb(3)))
The variable "cmyk" is declared thus.
B4X:
Private cmyk(4) As Float
This is the asJO function.
B4X:
Sub asJO(jo As JavaObject)As JavaObject
Return jo
End Sub
Keep getting errors.
main._t_tick (java line: 506)
java.lang.RuntimeException: Method: RgbCmykConverter not found in: b4j.example.main
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at b4j.example.main._t_tick(main.java:506)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.objects.Timer$TickTack$1.run(Timer.java:118)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
java.lang.RuntimeException: Method: RgbCmykConverter not found in: b4j.example.main
at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
at b4j.example.main._t_tick(main.java:506)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.objects.Timer$TickTack$1.run(Timer.java:118)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
What am I doing wrong here?
Regards.