鼠标显示颜色

发布于 2024-11-02 17:38:46 字数 226 浏览 1 评论 0原文

我正在尝试制作一个应用程序来显示我的鼠标指向的颜色,我不是指在我自己的应用程序中,而是在任何屏幕上的窗口中的任何位置,有点像我的鼠标指针旁边的标签,显示确切的颜色。

example

我是一名 Java 开发人员,但我不认为这可以在 Java 中完成,我想也许我需要某种脚本但我不知道是否会真正得到任何帮助

i am trying to make an application which would show which color my mouse is pointing to, i dont mean in my own application but anywhere in windows on any screen, kind of like a tag beside my mouse pointer which shows the exact color.

example

I am a Java developer but i dont think this could be done in java i am thinking maybe i need some sort of script but i have no idea any help would be really appriciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦罢 2024-11-09 17:38:47

随意选择: http://rosettacode.org/wiki/Color_of_a_screen_pixel

有一个 Java/AWT 示例, AutoHotKey 是一个简单的脚本选项。

第二个 C 示例显示了您需要的 3 个 API 调用 GetDC/GetCursorPos/GetPixel 及其支持代码,这些可以在为 Windows 编译的大多数语言中使用。

Take your pick: http://rosettacode.org/wiki/Color_of_a_screen_pixel

There is a Java/AWT example, an AutoHotKey is a simple scripted option.

The second C example shows the 3 API calls you need GetDC/GetCursorPos/GetPixel and their support code, these can be used from most languages that compile for windows.

猫腻 2024-11-09 17:38:46

该解决方案由两部分组成:

第 1 部分:检索颜色:

Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
Color color = new Robot().getPixelColor(mouseLocation.x, mouseLocation.y);

第 2 部分:获取颜色名称:

您可以从 维基百科的颜色列表。您可以根据 Wikipedia 上的数据在 Java 中创建映射。

也许您可以从几种颜色开始,并为未知颜色提供通用的十六进制表示,例如#rrggbb

The solution consists of two parts:

Part 1: Retrieving the color:

Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
Color color = new Robot().getPixelColor(mouseLocation.x, mouseLocation.y);

Part 2: Getting the color name:

You can get a list of many colors and their names from Wikipedia's List of colors. You can create a mapping in Java given the data on Wikipedia.

Perhaps you can start with a few colors, and provide a generic hex representation for unknown colors, for example #rrggbb.

盗琴音 2024-11-09 17:38:46

这是可运行的示例,

import java.awt.AWTException;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
public class Main {

public static String getHexString(int rgb) {
    String hexString = Integer.toHexString(rgb);
    hexString = hexString.length() > 1 ? hexString : "0" + hexString;
    return hexString;
}

public static void main(String[] a) throws AWTException {
    Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
    Color color = new Robot().getPixelColor(mouseLocation.x,
            mouseLocation.y);
    System.out.println(getHexString(color.getRed())
            + getHexString(color.getGreen())
            + getHexString(color.getBlue()));
}

}

Here is the runnable example,

import java.awt.AWTException;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
public class Main {

public static String getHexString(int rgb) {
    String hexString = Integer.toHexString(rgb);
    hexString = hexString.length() > 1 ? hexString : "0" + hexString;
    return hexString;
}

public static void main(String[] a) throws AWTException {
    Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
    Color color = new Robot().getPixelColor(mouseLocation.x,
            mouseLocation.y);
    System.out.println(getHexString(color.getRed())
            + getHexString(color.getGreen())
            + getHexString(color.getBlue()));
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文