Java Question How to pass images to a library

ivan.tellez

Active Member
Licensed User
Longtime User
Hi, I´m really new to java and libraries. I want to develop B4J libs but haven't found enough info. I'm using the jSimple Library Compiler and readed the basic tutorials.

The main obstacle I found is how to pass a Image to a lib, in java i have a function:

B4X:
Image tImg;

public void SendImage(Image img) {
        tImg = img;
}

Compiled and used in B4J Like this:

B4X:
Dim lib As Mylib
Dim pic As Image
pic.Initialize("C:\", "pic.png")
lib.SendImage(pic)

But I got the error:


error: inconvertible types

required: java.awt.Image
found: javafx.scene.image.Image


Is there a Complete Libraries Developers Guide? The tutorials are usefull, but the info is scattered and incomplete.


Thanks
 

ivan.tellez

Active Member
Licensed User
Longtime User
Hi, I changed the type in the sub on the java code and now B4J sends the image, but now the problem is in Java.

When I want to use the Image I got

(actual argument javafx.scene.image.Image cannot be converted to java.awt.Image by method invocation conversion)

Is there a way implemented on B4J to convert the image?
 

ivan.tellez

Active Member
Licensed User
Longtime User
Well, actually the code it was OK, only missing the conversion part.

But after all, I found the answer:

B4X:
Image tImg;

public void somesub(javafx.scene.image.Image img)
{
tImg = SwingFXUtils.fromFXImage(img, null);
}

Used from B4J:

B4X:
Dim pic As Image
pic.Initialize("C:\", "pic.png")
lib.SendImage(pic)


Now I can send from B4J a javafx.scene.image.Image as you stated and convert it to a java.awt.Image to use it on the java part.


I hope the little snippet will be useful to the community
 
Top