如何在 JavaFX 中获取像素的 RGB 值
我正在开始使用 JavaFX,基本上我想要实现的是一个颜色选择器。 起初,我想到了一个带有 LinearGradient 的矩形,它可以穿过所有原色/次要颜色。
看起来像我想要的,但问题是我无法获取此节点中给定坐标(x,y)处的 RGB 值。 我知道你可以通过任何形状的填充属性来做到这一点,如果它是颜色的话。
但是是否有办法获取 LinearGradient/Paint 内任何内容的 RGB 值?
I am getting started with JavaFX and basically what I am trying to implement is a Color Picker.
At first, I thought of having a rectangle with a LinearGradient that goes through all primary/secondary colors.
Looks like what I want, but the problem is that I can not get the RGB values at a given coordinate(x,y) in this Node.
I know you can do it through the fill property of any Shape IF it is a Color.
But Is there anyway to get the RGB values of anything inside a LinearGradient/Paint ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个 ColorPicker JavaFX 示例有帮助吗?
Does this ColorPicker JavaFX example help?
ColorPicker
JavaFX 示例以png
图像开始,该图像加载到image
,然后填充ImageView
。问题从包含
LinearGradient
的 JavaFXRectangle
开始。要将矩形内容放入缓冲图像中,可以使用 java.awt.Robot:
其中
rectangle
将描述包含感兴趣位的 JavaFX 矩形的坐标。robot.createScreenCapture
调用有一个问题,即要进行屏幕捕获,屏幕必须可见。 应该有更好的方法来填充缓冲图像,但我还没有遇到过。The
ColorPicker
JavaFX example starts with apng
image that is loaded to animage
that then populates theImageView
.The question starts with a JavaFX
Rectangle
containingLinearGradient
.To get the rectangle contents into a buffered image, one can use the java.awt.Robot:
where
rectangle
would be describe the coordinates of the JavaFX Rectangle containing the bits of interest.The
robot.createScreenCapture
call has the gotcha that to do the screen capture, the screen has to be visible. There should be a better of way to populate the buffered image but I've not yet encountered it.