微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JavaFX:盒子材质 vs. ImageView,为什么我的图像模糊?

如何解决JavaFX:盒子材质 vs. ImageView,为什么我的图像模糊?

我尝试使用图像作为素材在 Box显示图像,但发现显示在框上的图像模糊。

下面的代码显示Box 上的图像(模糊)与 ImageView 节点中按预期显示的相同图像之间的差异。

这是为什么?

package com.mycompany.testg;

import java.io.IOException;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.phongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import javafx.scene.paint.Color;
import javafx.scene.layout.VBox;


/**
 * JavaFX App
 */
public class App extends Application {

    String img = "https://image.flaticon.com/icons/png/512/741/741485.png";
    
    @Override
    public void start(Stage stage) throws IOException {
        Group grp = new Group();
        Box bx = new Box(512,512,1);
        phongMaterial mat = new phongMaterial();
        mat.setDiffuseMap(new Image(img));
        bx.setMaterial(mat);
        bx.setTranslateX(256);
        bx.setTranslateY(256);
        bx.setTranslateZ(0);

        ImageView iv = new ImageView(img);
        iv.setTranslateX(555);
        iv.setTranslateY(0);
        iv.setTranslateZ(0);

        grp.getChildren().addAll(bx,iv);
      
        Scene scene = new Scene(grp,1100,600,true);
        stage.setScene(scene);
        stage.show();
    }


    public static void main(String[] args) {
        launch();
    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。