如何在javaFX中混合两个图像 [英] How to Blend two Image in javaFX
本文介绍了如何在javaFX中混合两个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个关于存储在两个单独图像中的数据的图。我需要将它们放在一个图像中,这样我才能看出它的不同之处。如何在javaFX中完成此操作?
I have two plot about data that stored in two separate image. I need to place them in one Image so I can see the difference. How to accomplish this in javaFX?
推荐答案
解决方案
将两张图片放入群组并通过设置<应用 BlendMode a href =http://docs.oracle.com/javafx/2/api/javafx/scene/Node.html#blendModeProperty =noreferrer>最顶层节点的blendMode 。
Place the two images in a Group and apply a BlendMode by setting the blendMode of the topmost Node.
ImageView bottom = new ImageView(coke);
ImageView top = new ImageView(pepsi);
top.setBlendMode(BlendMode.DIFFERENCE);
Group blend = new Group(
bottom,
top
);
可执行样本
接受百事可乐的挑战?你能发现差异吗?
Take the Pepsi challenge? Can you "spot" the difference?
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中混合两个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文