如何在javaFX中混合两个图像

如何在javaFX中混合两个图像,javafx,Javafx,我有两个关于存储在两个单独图像中的数据的绘图。我需要把它们放在一张图片中,这样我才能看到它们的区别。如何在javaFX中实现这一点?解决方案 将两个图像放置在a中,并通过设置应用a 可执行样本 接受百事挑战?你能“发现”差异吗 import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Group; import javafx.scene.Scene; import javaf

我有两个关于存储在两个单独图像中的数据的绘图。我需要把它们放在一张图片中,这样我才能看到它们的区别。如何在javaFX中实现这一点?

解决方案

将两个图像放置在a中,并通过设置应用a

可执行样本

接受百事挑战?你能“发现”差异吗

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();
    }
}


嗯……我知道你在javaFX方面太有经验了,因为我在所有问题上都能从你的回答中得到帮助。。所以我想你可以帮我渡过难关。。提前谢谢
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();
    }
}