Skip to main content

JavaFX drawing performance

3 replies [Last post]
mipe
Offline
Joined: 2005-02-27
Points: 0

hi,

I am trying to develop a simple hand drawing tool as my first JavaFX application. The Polyline class seemed to be the handy solution to for the task.
I realized that the code quoted below gets pretty slow when the number of points in Polyline grows beyond some hundreds. On my PC (1200MHz Athlon) it is about 200 points where the drawing slows down.
I guess it slows down because of the frequent repainting calls of all the points (lines) of Polyline.

My question is whether JavaFX programming/scripting language and its ready made classes could provide better performance to support a hand drawing tool or any vector graphic like application? Or shall I dig deeper and implement my own canvas class or similar which does fast painting of the content when drawing on it?

Regards,
Peter

The hand drawing prototype listed below:

<br />
package test.draw;</p>
<p>import javafx.ui.*;<br />
import javafx.ui.canvas.*;<br />
import java.lang.System;</p>
<p>var drawing = new Polyline();</p>
<p>{<br />
    drawing.stroke = Color.RED;<br />
}</p>
<p>Frame {<br />
    title: "Polyline test"<br />
    width: 500<br />
    height: 500</p>
<p>    content:<br />
        Canvas {<br />
            content: bind drawing</p>
<p>            onMousePressed: function(event) {<br />
                insert [event.x, event.y] into drawing.points;<br />
            }</p>
<p>            onMouseReleased: function(event) {<br />
                System.out.println("number of lines: " + sizeof drawing.points);<br />
            }</p>
<p>            onMouseDragged: function(event) {<br />
                insert [event.x, event.y] into drawing.points;<br />
            }<br />
        }</p>
<p>  visible: true<br />
}<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mthornton
Offline
Joined: 2003-06-10
Points: 0

It is often faster to draw 10 polylines with 100 points each, than to draw 1 polyline with 1000 points.

mipe
Offline
Joined: 2005-02-27
Points: 0

yes, I would have expected so. I have slightly modified the code to "improve" the drawing speed, however, it seems to be as slow as the first version.

here the new code comes:

[code]
package test.draw;

import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.System;

var layers: Polyline[];

Frame {
title: "Polyline test"
width: 500
height: 500

content:
Canvas {
var drawing: Polyline
var numLines: Integer

content: bind layers

onMousePressed: function(event) {
drawing = new Polyline();
drawing.stroke = Color.RED;

insert drawing into layers;
insert [event.x, event.y] into drawing.points;
}

onMouseReleased: function(event) {
numLines += sizeof drawing.points;
System.out.println("number of lines: " + numLines);
}

onMouseDragged: function(event) {
insert [event.x, event.y] into drawing.points;
}
}

visible: true
}
[/code]

t_e_r
Offline
Joined: 2007-12-19
Points: 0

There is an issue at http://openjfx.java.sun.com/jira/browse/JFXC-758.
You might want to add to that.

In my case, my temporary work around was to draw my own Polyline as an image. But that runs into aliasing issues. In general, any graphical object or even images that have samples that crowd the number of pixels will need anti-aliasing filters, which would be compute-intensive for interactive scenarios.