0

I have ported some JAVA Apps from Windows 10 onto Ubuntu 22.04 (it runs alongside with Windows). Some data:

  • Acer e15. 360 GB Ubuntu-partition
  • Java JDK-9.0.4 (I won't move up due to one fact that JavaFX is a part of JDK and it saves me to deal with Open JavaFX) for both Windows and Ubuntu.

Most of the apps work fine. However I have noticed that JavaFX GraphicsContext won't work with Image on Ubuntu. On Windows 10 it works fine. The codes are

  scopter = new Image(getClass().getResourceAsStream("scopter.jpg"));
  Canvas screen = new Canvas(580, 500);
  gc = screen.getGraphicsContext2D();
  ...
  private void draw( ) {
    gc.setFill(Color.BLACK);
    gc.fillRect(0,0,580,580);
    gc.setFill(Color.RED);
    gc.drawImage(scopter, sX, sY); // <---Trouble is HERE
    if (mode) { // pick-up mode
      if (home > 1) { // chopper home
        gc.fillOval(cX, cY, 15, 15);
      } else if (home > 0) { // cargo home
        gc.fillOval(sX+DX, sY+DY, 15, 15);
      } else { // on fetching cargo
        if (home < 0) { // outbound
          gc.setStroke(Color.RED);
          gc.fillOval(cargoX, cargoY, 15, 15);
          gc.strokeText("Invalid Cargo Location.", 200, 250);
        } else gc.fillOval(cX, cY, 15, 15);
      }
    } else { // delivery mode
      if (home > 0) { // chopper home
        gc.fillOval(dX, dY, 15, 15);
      } else { // on fetching cargo
        if (home < 0) { // outbound
          gc.setStroke(Color.RED);
          gc.fillOval(cargoX, cargoY, 15, 15);
          gc.strokeText("Invalid Cargo Location.", 200, 250);
        } else {
          if (delivery > 0) {
            gc.fillOval(sX+DX, sY+DY, 15, 15);
          } else gc.fillOval(cargoX, cargoY, 15, 15);
        }
      }
      if (dX > 0) {
        gc.setFill(Color.WHITE);
        gc.fillOval(dX+5, dY+5, 5, 5);
      }
    }
    gc.setLineWidth(1);
    gc.setStroke(Color.YELLOW);
    gc.strokeText("FuzzyLogic Controlled Aerial Chopper - Joe Nartca (C) -", 124, 15);
    gc.strokeText(String.format("Speed %3.2f, Chopper %3.2f / %3.2f (cargo %3.2f / %3.2f)",
                                speed, sX, sY, cX, cY), 108, 30);
    gc.setStroke(Color.CYAN);
    gc.strokeText(String.format("Distance to TARGET and GOAL  %3.2f / %3.2f",
                                deltaX, deltaY),5, 495);
    if (oX != 0) {
      gc.setFill(Color.web("#a9ff00"));
      gc.fillOval(oX, oY, 20, 20);
    }
  }

The Screen layout And as one can see that the scopter image aside the red ball won't show up. The question is: is it a glitch of Ubuntu 22.04 or of JavaFX-linux?

PS: And here is the Image on Windows

1 Answers1

0

...I found the problem that makes me thinking about the bug whether it is JFX bug (JDK 9.04) or it is an Ubuntu problem with JPG image. I have reduced my JFX app and tried to draw 2 images on JFX canvas: one is a JPG image and the other is a PNG image. And what I see is that PNG image is painted, but the JPG image gets lost. Here is the reduced app:

// JavaFX
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.layout.*;
import javafx.scene.control.*;
import javafx.geometry.*;
import javafx.scene.canvas.*;
import javafx.scene.paint.Color;
import javafx.scene.image.Image;
// FuzzyLogic
import fuzzylogic.*;
//
// FuzzyLogic Controlled Unmanned Aerial Chopper
// Joe Nartca (C)
//
public class MissingImage extends Application {
  public void start(Stage stage) {
    stage.setTitle("FuzzyLogic Controlled Drone -JoeNartca (C)-");
    try {
        scopter_jpg = new Image(new java.io.FileInputStream("scopter.jpg"));
        scopter_png = new Image(new java.io.FileInputStream("scopter.png"));
    } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(0);
    }
    Canvas screen = new Canvas(580, 500);
    gc = screen.getGraphicsContext2D();
     gc = screen.getGraphicsContext2D();
    // fill canvas
    draw( );
    //
    VBox root = new VBox(10);
    root.setAlignment(Pos.CENTER);
    root.setPadding(new Insets(5,5,5,5));
    root.getChildren().addAll(screen);
    Scene scene = new Scene(root, 590, 590);
    // either inline styling or via file css.css
    stage.setScene(scene);
    stage.show();
  }
  // clean up before terminated
  public void stop() {
    Platform.exit();
    System.exit(0);
  }
    // paint the Canvas
  private void draw( ) {
    gc.setFill(Color.BLACK);
    gc.fillRect(0,0,580,580);
    gc.setFill(Color.RED);
    gc.drawImage(scopter_jpg, 290, 290); // Draw JPG image
    gc.drawImage(scopter_png, 320, 320); // Draw PNG image
    gc.fillOval(535, 480, 15, 15);
    gc.fillOval(510, 480, 15, 15);
    gc.setLineWidth(1);
    gc.setStroke(Color.YELLOW);
    gc.strokeText("FuzzyLogic Controlled Flying Drone - Joe Nartca (C) -", 124, 15);
  }
  private Image scopter_jpg, scopter_png;
  private GraphicsContext gc;
  public static void main(String... argv) {
      Application.launch();
  }
}

and the Screenshot the jpg image JPG Image the png imagePNG Image