Created
February 28, 2014 07:17
-
-
Save jewelsea/9266737 to your computer and use it in GitHub Desktop.
JavaFX BlendMode.DIFFERENCE sample.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javafx.application.Application; | |
import javafx.geometry.Insets; | |
import javafx.scene.Group; | |
import javafx.scene.Scene; | |
import javafx.scene.effect.BlendMode; | |
import javafx.scene.image.Image; | |
import javafx.scene.image.ImageView; | |
import javafx.scene.layout.HBox; | |
import javafx.stage.Stage; | |
/** Blend a coke can and a pepsi can to find the difference. */ | |
public class PepsiChallenge extends Application { | |
@Override | |
public void start(Stage stage) { | |
Image coke = new Image( | |
"http://icons.iconarchive.com/icons/michael/coke-pepsi/256/Coca-Cola-Can-icon.png" | |
); | |
Image pepsi = new Image( | |
"http://icons.iconarchive.com/icons/michael/coke-pepsi/256/Pepsi-Can-icon.png" | |
); | |
ImageView bottom = new ImageView(coke); | |
ImageView top = new ImageView(pepsi); | |
top.setBlendMode(BlendMode.DIFFERENCE); | |
Group blend = new Group( | |
bottom, | |
top | |
); | |
HBox layout = new HBox(10); | |
layout.getChildren().addAll( | |
new ImageView(coke), | |
blend, | |
new ImageView(pepsi) | |
); | |
layout.setPadding(new Insets(10)); | |
stage.setScene(new Scene(layout)); | |
stage.show(); | |
} | |
public static void main(String[] args) { | |
launch(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer to StackOverflow question: How to Blend two Images in JavaFX.