【问题标题】:Partially transparent images in javafxjavafx中的部分透明图像
【发布时间】:2017-03-21 20:24:36
【问题描述】:

我正在 Eclipse 中制作一个项目。我已经使用“图像视图”选项上传了一个 .png 文件。它有一些透明区域。我想编写代码,以便它只检测用户鼠标在不透明区域上的点击并将该用户带到一个新窗口由我定义。

【问题讨论】:

    标签: java javafx png desktop-application scenebuilder


    【解决方案1】:

    这段代码应该在大多数情况下都可以工作。

    imageView.addEventFilter(MouseEvent.MOUSE_CLICKED, e -> {
        Color color = image.getPixelReader().getColor(e.getX(),e.getY()));
        if(color.getAlpha() != 0)
        {
            //execute your code here
        }
    });
    

    【讨论】:

    • @mistletoe 接受我的回答会很棒。
    猜你喜欢
    • 2012-02-24
    • 2019-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-04
    • 1970-01-01
    • 2016-03-31
    • 2019-01-30
    相关资源
    最近更新 更多