|
|
|
|
JavaFX drawing performance
Posted:
May 14, 2008 5:43 PM
|
|
|
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:
package test.draw;
import javafx.ui.*;
import javafx.ui.canvas.*;
import java.lang.System;
var drawing = new Polyline();
{
drawing.stroke = Color.RED;
}
Frame {
title: "Polyline test"
width: 500
height: 500
content:
Canvas {
content: bind drawing
onMousePressed: function(event) {
insert [event.x, event.y] into drawing.points;
}
onMouseReleased: function(event) {
System.out.println("number of lines: " + sizeof drawing.points);
}
onMouseDragged: function(event) {
insert [event.x, event.y] into drawing.points;
}
}
visible: true
}
|
|
|
|
|
|
|
Re: JavaFX drawing performance
Posted:
May 15, 2008 4:45 AM
in response to: mipe
|
|
|
It is often faster to draw 10 polylines with 100 points each, than to draw 1 polyline with 1000 points.
|
|
|
|
|
|
|
|
Re: JavaFX drawing performance
Posted:
May 15, 2008 2:45 PM
in response to: mthornton
|
|
|
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:
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
}
|
|
|
|
|
|
|
|
Re: JavaFX drawing performance
Posted:
May 16, 2008 12:27 PM
in response to: mipe
|
 |
Helpful |
|
|
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.
|
|
|
|
|