JavaFX and antialias


Question

I am in the process of porting some graphics rendering from java/Android to standard java.

The first thing that I am faced with is - which graphics api to use, Graphics2D or JavaFX. It was proposed by assylias in my previous question "Porting graphics drawing from android to standard java", that I use JavaFX.

I have seen that this has the advantage of taking doubles and floats as parameters for drawing, as with Android. However, I have not been able to find anything which confirms that the drawing is antialiased, or that antialiasing can be turned on.

My objective is to generate a high quality image which will be directly saved to disk and not displayed in the application. It will be displayed in another context and not printed. I need to be drawing text, paths, beziers, lines, ellipses and rectangles.

Is it worth my while digging into JavaFX or do I have no choice but to go with Graphics2D ?

1
2
5/23/2017 12:16:31 PM

Accepted Answer

Many (if not all) of the objects that are drawn in JavaFX applications already have antialiasing effect. This is visible to the naked eye. Try to write two identical applications, one in JavaFX, and another in Swing (without antialiasing effect of Graphics and RenderingHints object). The difference is clear, especially when drawing geometric shapes and text. Here you can find some comparisons between Swing and JavaFX, and here you can get to know better the JavaFX 2.X (read the subject "Graphics System" and "Media and Images").

Personally, I would prefer to use JavaFX technology. I previously used a lot Swing. Each of my applications had to be made in Swing. However, after seeing the practicality of JavaFX, its maintainability, its elegance and productivity, I did not think twice. Even if you just want to draw simple things, JavaFX seems to have a much better performance. If I'm not mistaken, JavaFX was developed taking into account the use of video hardware on your platform, and was also inspired by the famous game engines available for Java users, which are made to work with high processing visual effect, screen updates, and among many other things.

For you marvel a bit with the technology and effort that was put, I beg you, visit this address. Look for the download of a JavaFX program named Ensemble. You will find where is written "JDK 7 and JavaFX Demos and Samples". click download and use the demo program Ensemble.

For information on drawing text, geometric shapes and stuff, see the following links:

http://java.dzone.com/articles/javafx-21-beta-improved-font

http://fxexperience.com/2012/01/lcd-text-support-in-javafx-2-1-developer-preview/ (An alternative from the previous link)

http://docs.oracle.com/javafx/2/text/jfxpub-text.htm (Look for "Setting LCD Text Support" and also, with the feature of applying effects to text and various things of JavaFX, you can still improve the visualization of what is shown to the user.)

http://docs.oracle.com/javafx/2/api/javafx/scene/shape/Shape.html#smoothProperty (The "shapes part")

Would you like an opinion of a colleague? Adopt JavaFX in its version 2.X or higher (do not use the JavaFX 1.X). Over time this type of technology will mature. Much still come ahead. The next update of JavaFX, we will have many nice features. And notice that JavaFX is still in its version 2.X. Probably in the near future Swing library will be left out, as happened with the AWT. You better start now studying JavaFX, rather than only in the future you go familiarizing yourself. The market is there.

If you still have some questions, please come back and ask. We'll be here. :)

Good luck.

2
1/19/2014 6:25:48 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon