JavaFX on Raspberry Pi Zero W: Slow Transition Effects (low fps)












1















I quick and dirty programmed a very small image slide show application using javafx to run on my Raspberry Pi Zero W. In this application I am using FadeTransition for the images. It's all working fine but I unfortunately have the issue that it's quite slow, so the fade transitions don't look smooth (too low fps).



First, I increased the vRam to 128Mb (I also tried 256Mb before).Then, I played around with these parameters in various combinations:



-Dprism.forceGPU=true



-Dprism.order=j2d,sw



-Dsun.java2d.opengl=true



I even overclocked the pi to 1100Mhz. But the problem still remains, the transition effects are still very slow.



I also tried to run my application without lightdm as I read multiple times on the internet that java is able to write directly to the display buffer. But I could not get the application to run this way.



Do you have an idea if it's even possible to run this smoothly on a raspberry pi zero?



Thank you very much!





Snippet of my java code:



FileInputStream input = null;
FadeTransition fadeIn = new FadeTransition(Duration.millis(transitionTime * 1000 / 2), imageView);
fadeIn.setFromValue(0);
fadeIn.setToValue(1.0);
fadeIn.setInterpolator(Interpolator.LINEAR);

FadeTransition fadeOut = new FadeTransition(Duration.millis(transitionTime * 1000 / 2), imageView);

fadeOut.setFromValue(1.0);
fadeOut.setToValue(0);
fadeOut.setInterpolator(Interpolator.LINEAR);

Thread t = new Thread(new Runnable() {

@Override
public void run() {

while (true) {
try {
long currentTime = System.currentTimeMillis();

if (currentTime > lastRefreshTime + showingTimePerImage * 1000) {

File file = getNewRandomFileFromFolder();

input = new FileInputStream(file.getAbsolutePath());
Image image = new Image(input);

fadeOut.setOnFinished(new EventHandler < ActionEvent > () {
@Override
public void handle(ActionEvent arg0) {
imageView.setImage(image);
imageView.setPreserveRatio(true);
imageView.fitHeightProperty().bind(primaryStage.heightProperty());
fadeIn.play();
}
});

fadeOut.play();

lastRefreshTime = currentTime;
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}









share|improve this question




















  • 2





    I do not know JavaFX, but I wonder if it has something to do with your threading. Perhaps you should show more of your code, where you make the threads and run them. Also, is it kosher to be manipulating the user-interface with your image display from a background thread?

    – Basil Bourque
    Nov 26 '18 at 7:26






  • 1





    @BasilBourque - manipulating the UI from a background thread is not allowed in JavaFX, however - the onFinished event of any JavaFX animation is guaranteed to be called on the UI thread, so there is no problem there. There is however a question of whether the loop is indeed running on a separate thread. @user1250100 - can you share the part of the code which actually starts the thread? You might also want to consider using Thread.sleep so the loop is less resource-intensive, or maybe use Timer#scheduleAtFixedRate.

    – Itai
    Nov 26 '18 at 7:51






  • 1





    @Itai Regarding the issue of being on the UI thread, notice that fadeOut.play is being called outside of that setOnFinished. Might that be a UI manipulation from the background thread?

    – Basil Bourque
    Nov 26 '18 at 8:02











  • Thank you very much for your comments! I uploaded my complete file (it's really just one) here: pastebin.com/N6KwZ4Gt You can take a look, I will check your hints later, thanks! :-)

    – Sven
    Nov 26 '18 at 8:18













  • Hey there, I thought about your hints. I see that there are javafx function calls in my worker thread. I didn't know that its a problem. Would it in your opinion better to just set an flag in the worker thread and check this within the ui thread for being changed to initiate the image fade? Thread0: javafx + check flag, Thread1: Timer + load image + set flag Better this way? Thank you!

    – Sven
    Nov 27 '18 at 6:02


















1















I quick and dirty programmed a very small image slide show application using javafx to run on my Raspberry Pi Zero W. In this application I am using FadeTransition for the images. It's all working fine but I unfortunately have the issue that it's quite slow, so the fade transitions don't look smooth (too low fps).



First, I increased the vRam to 128Mb (I also tried 256Mb before).Then, I played around with these parameters in various combinations:



-Dprism.forceGPU=true



-Dprism.order=j2d,sw



-Dsun.java2d.opengl=true



I even overclocked the pi to 1100Mhz. But the problem still remains, the transition effects are still very slow.



I also tried to run my application without lightdm as I read multiple times on the internet that java is able to write directly to the display buffer. But I could not get the application to run this way.



Do you have an idea if it's even possible to run this smoothly on a raspberry pi zero?



Thank you very much!





Snippet of my java code:



FileInputStream input = null;
FadeTransition fadeIn = new FadeTransition(Duration.millis(transitionTime * 1000 / 2), imageView);
fadeIn.setFromValue(0);
fadeIn.setToValue(1.0);
fadeIn.setInterpolator(Interpolator.LINEAR);

FadeTransition fadeOut = new FadeTransition(Duration.millis(transitionTime * 1000 / 2), imageView);

fadeOut.setFromValue(1.0);
fadeOut.setToValue(0);
fadeOut.setInterpolator(Interpolator.LINEAR);

Thread t = new Thread(new Runnable() {

@Override
public void run() {

while (true) {
try {
long currentTime = System.currentTimeMillis();

if (currentTime > lastRefreshTime + showingTimePerImage * 1000) {

File file = getNewRandomFileFromFolder();

input = new FileInputStream(file.getAbsolutePath());
Image image = new Image(input);

fadeOut.setOnFinished(new EventHandler < ActionEvent > () {
@Override
public void handle(ActionEvent arg0) {
imageView.setImage(image);
imageView.setPreserveRatio(true);
imageView.fitHeightProperty().bind(primaryStage.heightProperty());
fadeIn.play();
}
});

fadeOut.play();

lastRefreshTime = currentTime;
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}









share|improve this question




















  • 2





    I do not know JavaFX, but I wonder if it has something to do with your threading. Perhaps you should show more of your code, where you make the threads and run them. Also, is it kosher to be manipulating the user-interface with your image display from a background thread?

    – Basil Bourque
    Nov 26 '18 at 7:26






  • 1





    @BasilBourque - manipulating the UI from a background thread is not allowed in JavaFX, however - the onFinished event of any JavaFX animation is guaranteed to be called on the UI thread, so there is no problem there. There is however a question of whether the loop is indeed running on a separate thread. @user1250100 - can you share the part of the code which actually starts the thread? You might also want to consider using Thread.sleep so the loop is less resource-intensive, or maybe use Timer#scheduleAtFixedRate.

    – Itai
    Nov 26 '18 at 7:51






  • 1





    @Itai Regarding the issue of being on the UI thread, notice that fadeOut.play is being called outside of that setOnFinished. Might that be a UI manipulation from the background thread?

    – Basil Bourque
    Nov 26 '18 at 8:02











  • Thank you very much for your comments! I uploaded my complete file (it's really just one) here: pastebin.com/N6KwZ4Gt You can take a look, I will check your hints later, thanks! :-)

    – Sven
    Nov 26 '18 at 8:18













  • Hey there, I thought about your hints. I see that there are javafx function calls in my worker thread. I didn't know that its a problem. Would it in your opinion better to just set an flag in the worker thread and check this within the ui thread for being changed to initiate the image fade? Thread0: javafx + check flag, Thread1: Timer + load image + set flag Better this way? Thank you!

    – Sven
    Nov 27 '18 at 6:02
















1












1








1


1






I quick and dirty programmed a very small image slide show application using javafx to run on my Raspberry Pi Zero W. In this application I am using FadeTransition for the images. It's all working fine but I unfortunately have the issue that it's quite slow, so the fade transitions don't look smooth (too low fps).



First, I increased the vRam to 128Mb (I also tried 256Mb before).Then, I played around with these parameters in various combinations:



-Dprism.forceGPU=true



-Dprism.order=j2d,sw



-Dsun.java2d.opengl=true



I even overclocked the pi to 1100Mhz. But the problem still remains, the transition effects are still very slow.



I also tried to run my application without lightdm as I read multiple times on the internet that java is able to write directly to the display buffer. But I could not get the application to run this way.



Do you have an idea if it's even possible to run this smoothly on a raspberry pi zero?



Thank you very much!





Snippet of my java code:



FileInputStream input = null;
FadeTransition fadeIn = new FadeTransition(Duration.millis(transitionTime * 1000 / 2), imageView);
fadeIn.setFromValue(0);
fadeIn.setToValue(1.0);
fadeIn.setInterpolator(Interpolator.LINEAR);

FadeTransition fadeOut = new FadeTransition(Duration.millis(transitionTime * 1000 / 2), imageView);

fadeOut.setFromValue(1.0);
fadeOut.setToValue(0);
fadeOut.setInterpolator(Interpolator.LINEAR);

Thread t = new Thread(new Runnable() {

@Override
public void run() {

while (true) {
try {
long currentTime = System.currentTimeMillis();

if (currentTime > lastRefreshTime + showingTimePerImage * 1000) {

File file = getNewRandomFileFromFolder();

input = new FileInputStream(file.getAbsolutePath());
Image image = new Image(input);

fadeOut.setOnFinished(new EventHandler < ActionEvent > () {
@Override
public void handle(ActionEvent arg0) {
imageView.setImage(image);
imageView.setPreserveRatio(true);
imageView.fitHeightProperty().bind(primaryStage.heightProperty());
fadeIn.play();
}
});

fadeOut.play();

lastRefreshTime = currentTime;
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}









share|improve this question
















I quick and dirty programmed a very small image slide show application using javafx to run on my Raspberry Pi Zero W. In this application I am using FadeTransition for the images. It's all working fine but I unfortunately have the issue that it's quite slow, so the fade transitions don't look smooth (too low fps).



First, I increased the vRam to 128Mb (I also tried 256Mb before).Then, I played around with these parameters in various combinations:



-Dprism.forceGPU=true



-Dprism.order=j2d,sw



-Dsun.java2d.opengl=true



I even overclocked the pi to 1100Mhz. But the problem still remains, the transition effects are still very slow.



I also tried to run my application without lightdm as I read multiple times on the internet that java is able to write directly to the display buffer. But I could not get the application to run this way.



Do you have an idea if it's even possible to run this smoothly on a raspberry pi zero?



Thank you very much!





Snippet of my java code:



FileInputStream input = null;
FadeTransition fadeIn = new FadeTransition(Duration.millis(transitionTime * 1000 / 2), imageView);
fadeIn.setFromValue(0);
fadeIn.setToValue(1.0);
fadeIn.setInterpolator(Interpolator.LINEAR);

FadeTransition fadeOut = new FadeTransition(Duration.millis(transitionTime * 1000 / 2), imageView);

fadeOut.setFromValue(1.0);
fadeOut.setToValue(0);
fadeOut.setInterpolator(Interpolator.LINEAR);

Thread t = new Thread(new Runnable() {

@Override
public void run() {

while (true) {
try {
long currentTime = System.currentTimeMillis();

if (currentTime > lastRefreshTime + showingTimePerImage * 1000) {

File file = getNewRandomFileFromFolder();

input = new FileInputStream(file.getAbsolutePath());
Image image = new Image(input);

fadeOut.setOnFinished(new EventHandler < ActionEvent > () {
@Override
public void handle(ActionEvent arg0) {
imageView.setImage(image);
imageView.setPreserveRatio(true);
imageView.fitHeightProperty().bind(primaryStage.heightProperty());
fadeIn.play();
}
});

fadeOut.play();

lastRefreshTime = currentTime;
}
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
}






java javafx raspberry-pi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 7:05







Sven

















asked Nov 26 '18 at 6:59









SvenSven

153




153








  • 2





    I do not know JavaFX, but I wonder if it has something to do with your threading. Perhaps you should show more of your code, where you make the threads and run them. Also, is it kosher to be manipulating the user-interface with your image display from a background thread?

    – Basil Bourque
    Nov 26 '18 at 7:26






  • 1





    @BasilBourque - manipulating the UI from a background thread is not allowed in JavaFX, however - the onFinished event of any JavaFX animation is guaranteed to be called on the UI thread, so there is no problem there. There is however a question of whether the loop is indeed running on a separate thread. @user1250100 - can you share the part of the code which actually starts the thread? You might also want to consider using Thread.sleep so the loop is less resource-intensive, or maybe use Timer#scheduleAtFixedRate.

    – Itai
    Nov 26 '18 at 7:51






  • 1





    @Itai Regarding the issue of being on the UI thread, notice that fadeOut.play is being called outside of that setOnFinished. Might that be a UI manipulation from the background thread?

    – Basil Bourque
    Nov 26 '18 at 8:02











  • Thank you very much for your comments! I uploaded my complete file (it's really just one) here: pastebin.com/N6KwZ4Gt You can take a look, I will check your hints later, thanks! :-)

    – Sven
    Nov 26 '18 at 8:18













  • Hey there, I thought about your hints. I see that there are javafx function calls in my worker thread. I didn't know that its a problem. Would it in your opinion better to just set an flag in the worker thread and check this within the ui thread for being changed to initiate the image fade? Thread0: javafx + check flag, Thread1: Timer + load image + set flag Better this way? Thank you!

    – Sven
    Nov 27 '18 at 6:02
















  • 2





    I do not know JavaFX, but I wonder if it has something to do with your threading. Perhaps you should show more of your code, where you make the threads and run them. Also, is it kosher to be manipulating the user-interface with your image display from a background thread?

    – Basil Bourque
    Nov 26 '18 at 7:26






  • 1





    @BasilBourque - manipulating the UI from a background thread is not allowed in JavaFX, however - the onFinished event of any JavaFX animation is guaranteed to be called on the UI thread, so there is no problem there. There is however a question of whether the loop is indeed running on a separate thread. @user1250100 - can you share the part of the code which actually starts the thread? You might also want to consider using Thread.sleep so the loop is less resource-intensive, or maybe use Timer#scheduleAtFixedRate.

    – Itai
    Nov 26 '18 at 7:51






  • 1





    @Itai Regarding the issue of being on the UI thread, notice that fadeOut.play is being called outside of that setOnFinished. Might that be a UI manipulation from the background thread?

    – Basil Bourque
    Nov 26 '18 at 8:02











  • Thank you very much for your comments! I uploaded my complete file (it's really just one) here: pastebin.com/N6KwZ4Gt You can take a look, I will check your hints later, thanks! :-)

    – Sven
    Nov 26 '18 at 8:18













  • Hey there, I thought about your hints. I see that there are javafx function calls in my worker thread. I didn't know that its a problem. Would it in your opinion better to just set an flag in the worker thread and check this within the ui thread for being changed to initiate the image fade? Thread0: javafx + check flag, Thread1: Timer + load image + set flag Better this way? Thank you!

    – Sven
    Nov 27 '18 at 6:02










2




2





I do not know JavaFX, but I wonder if it has something to do with your threading. Perhaps you should show more of your code, where you make the threads and run them. Also, is it kosher to be manipulating the user-interface with your image display from a background thread?

– Basil Bourque
Nov 26 '18 at 7:26





I do not know JavaFX, but I wonder if it has something to do with your threading. Perhaps you should show more of your code, where you make the threads and run them. Also, is it kosher to be manipulating the user-interface with your image display from a background thread?

– Basil Bourque
Nov 26 '18 at 7:26




1




1





@BasilBourque - manipulating the UI from a background thread is not allowed in JavaFX, however - the onFinished event of any JavaFX animation is guaranteed to be called on the UI thread, so there is no problem there. There is however a question of whether the loop is indeed running on a separate thread. @user1250100 - can you share the part of the code which actually starts the thread? You might also want to consider using Thread.sleep so the loop is less resource-intensive, or maybe use Timer#scheduleAtFixedRate.

– Itai
Nov 26 '18 at 7:51





@BasilBourque - manipulating the UI from a background thread is not allowed in JavaFX, however - the onFinished event of any JavaFX animation is guaranteed to be called on the UI thread, so there is no problem there. There is however a question of whether the loop is indeed running on a separate thread. @user1250100 - can you share the part of the code which actually starts the thread? You might also want to consider using Thread.sleep so the loop is less resource-intensive, or maybe use Timer#scheduleAtFixedRate.

– Itai
Nov 26 '18 at 7:51




1




1





@Itai Regarding the issue of being on the UI thread, notice that fadeOut.play is being called outside of that setOnFinished. Might that be a UI manipulation from the background thread?

– Basil Bourque
Nov 26 '18 at 8:02





@Itai Regarding the issue of being on the UI thread, notice that fadeOut.play is being called outside of that setOnFinished. Might that be a UI manipulation from the background thread?

– Basil Bourque
Nov 26 '18 at 8:02













Thank you very much for your comments! I uploaded my complete file (it's really just one) here: pastebin.com/N6KwZ4Gt You can take a look, I will check your hints later, thanks! :-)

– Sven
Nov 26 '18 at 8:18







Thank you very much for your comments! I uploaded my complete file (it's really just one) here: pastebin.com/N6KwZ4Gt You can take a look, I will check your hints later, thanks! :-)

– Sven
Nov 26 '18 at 8:18















Hey there, I thought about your hints. I see that there are javafx function calls in my worker thread. I didn't know that its a problem. Would it in your opinion better to just set an flag in the worker thread and check this within the ui thread for being changed to initiate the image fade? Thread0: javafx + check flag, Thread1: Timer + load image + set flag Better this way? Thank you!

– Sven
Nov 27 '18 at 6:02







Hey there, I thought about your hints. I see that there are javafx function calls in my worker thread. I didn't know that its a problem. Would it in your opinion better to just set an flag in the worker thread and check this within the ui thread for being changed to initiate the image fade? Thread0: javafx + check flag, Thread1: Timer + load image + set flag Better this way? Thank you!

– Sven
Nov 27 '18 at 6:02














0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476084%2fjavafx-on-raspberry-pi-zero-w-slow-transition-effects-low-fps%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53476084%2fjavafx-on-raspberry-pi-zero-w-slow-transition-effects-low-fps%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks