轻松选择屏幕上的像素并获取颜色和绝对坐标的工具

Fla*_*ash 19 software-recommendation

我正在寻找一种工具,可以让我选择屏幕上的任何像素并获取其 RGB 颜色和绝对 (x, y) 位置。

我在 Windows 上使用了一些工具,这些工具显示一个带有十字准线的大放大方块,让我可以轻松选择我想要的像素并获取其详细信息。

ubuntu 有这样的东西吗?

sla*_*ack 13

有一个名为gpick的工具。

在这里您可以看到该工具的图像。使用 gpick,您可以选择像素、查看 HTML 代码、向调色板添加颜色并生成颜色。

要使用它,请右键单击六边形的中间,然后使用空格键将颜色保存到调色板中。

选择


sno*_*guy 6

我相信这会让你得到你想要的。诚然,这是几步,但看起来比现在更糟,因为我展示了每一个小步骤。

设置

安装 ImageMagick 和快门。

sudo apt-get install imagemagick shutter
Run Code Online (Sandbox Code Playgroud)

如何获得 x,y 坐标和颜色

A.打开Shutter并点击选择按钮

点击选择按钮的图片

B. 请注意,当您四处移动鼠标时,它会显示您正在寻找的 x,y 坐标。

在此处输入图片说明

当您找到正确的位置后,继续单击鼠标按钮并绘制一个正方形以捕获图像。(只要您在感兴趣的像素上开始(左上角),您的图像有多大并不重要。)

在此处输入图片说明

C. 在快门中关闭图像

在此处输入图片说明

D. 从终端运行以下命令。这将为您提供左上角像素的颜色值。

convert ~/Pictures/Selection_001.png -crop 1x1+1+1 txt:- | sed -n 's/.* \(#.*\)/\1/p' 
Run Code Online (Sandbox Code Playgroud)

E. 在命令行中继续删除图像,以便下次快门拍摄照片时,它会为其命名相同的名称。(否则您需要在上一步 (D) 中调整名称。

rm ~/Pictures/Selection_001.png
Run Code Online (Sandbox Code Playgroud)


Ian*_* B. 6

将此代码粘贴到文本编辑器中,使其可执行并运行。当您使用吸管选择颜色时,x 和 y 坐标将出现在顶部。

编辑:编写代码以添加缩放窗口。要让它抓取窗口外的像素,请单击按钮(而不是滴管)。再次单击该按钮可停止抓取指针。还没有弄清楚如何用 cairo 绘制十字准线,但您可能可以按原样使用。我在那里留下了一些开罗代码,以防有人能告诉我为什么我的矩形不绘制......

#!/usr/bin/python
from gi.repository import Gtk,Gdk, GdkPixbuf
import cairo

class picker(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.connect('delete-event', Gtk.main_quit)
        self.connect('motion-notify-event', self.motion_cb)
        self.connect('button-press-event',self.button_press)
        box=Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)

        #Setup area for coordinates and zoom window
        coordbox=Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.xcoor=Gtk.Label("x: ")
        coordbox.pack_start(self.xcoor, True, False, 1)
        self.ycoor=Gtk.Label("y: ")
        coordbox.pack_start(self.ycoor, True, False, 1)
        self.zoomwin=Gtk.Image()
        #Trying to draw on Gtk.Image with cairo for crosshairs... Not working
        self.zoomwin.connect('draw', self.draw) 
        self.zoomwin.set_app_paintable(True)
        coordbox.pack_start(self.zoomwin,True,True,1)
        self.buttongo=Gtk.Button("Pick Color")
        self.buttongo.connect('clicked',self.gobutton_activate)
        coordbox.pack_start(self.buttongo,True,True,1)
        box.pack_start(coordbox, True, False, 5)

        #Put in color wheel for tweaking color
        self.cp=Gtk.ColorSelection()
        self.cp.connect('color-changed', self.on_color_changed)
        box.pack_start(self.cp, True, True, 5)
        self.add(box)
        self.show_all()

        #Set some initial parameters
        self.w,self.h=10,10 #Size of zoomed image in pixels
        self.count=0
        self.window=self.get_window()
        #set initial zoom image
        self.zoomwin.set_from_pixbuf(self.get_image().scale_simple(240,240,GdkPixbuf.InterpType.TILES))
        self.grabbing=False

    def on_color_changed(self,widget=None, data=None):
        #Print out x,y to widgets
        display=Gdk.Display.get_default()
        (screen,x,y,modifier)=display.get_pointer()
        self.xcoor.set_text("x: %i" %x)
        self.ycoor.set_text("y: %i" %y)


    def get_image(self,w=None,h=None):
        #Get a pixbuff image under pointer
        if w==None: w=self.w
        if h==None: h=self.h
        display=Gdk.Display.get_default()
        (screen,self.x,self.y,modifier)=display.get_pointer()
        window=Gdk.get_default_root_window()
        screenshot = Gdk.pixbuf_get_from_window(window,
            self.x-int(w/2), self.y-int(h/2), int(w), int(h))
        return screenshot

    def motion_cb(self, widget, data):
        #What to do while mouse pointer is moving
        #DONT capture every event! Causes too much backup
        if self.count==5:
            self.pixbuf=self.get_image().scale_simple(240,240,GdkPixbuf.InterpType.TILES)
            self.zoomwin.set_from_pixbuf(self.pixbuf)
            self.zoomwin.queue_draw()
            self.count=0
        self.count+=1

    def grab_start(self):
        #Grab control of pointer outside of window
        self.grabbing = True
        Gdk.pointer_grab(self.window, 
                        True, #allow passage of pointer events to children
                        Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK,
                        None,
                        None,# could put a custom cursor here
                        0L)

    def button_press(self,widget,data):
        #capture color under the pointer and set the color selection
        cenpx=self.get_image(1,1)
        color=tuple(map(ord, cenpx.get_pixels()[:3]))
        col=Gdk.RGBA(float(color[0])/256.,float(color[1])/256.,float(color[2])/256.)
        self.cp.set_current_rgba(col)

    def grab_stop(self):
        #Stop Grabbing the pointer
        Gdk.pointer_ungrab(0)
        self.grabbing=False     

    def gobutton_activate(self, widget, data=None):
        #Button control
        if self.grabbing==False:
            self.grab_start()
            widget.set_label("Stop Picking")
        else:
            self.grab_stop()
            widget.set_label("Pick Color")

    def draw(self, widget, cr):
        #this gets called, but nothing is drawn that I can see...
        cr.set_operator(cairo.OPERATOR_SOURCE)
        cr.set_source_rgba(1,1,1,1)
        w = self.w
        h = self.h
        cr.set_source_rgba(1,1,1,1)
        cr.set_line_width(10)
        cr.rectangle(w/2-1,h/2-1,w/2+1,h/2+1)
        cr.stroke()
        cr.set_operator(cairo.OPERATOR_OVER)


if __name__=="__main__":
    win=picker()
    Gtk.main()
Run Code Online (Sandbox Code Playgroud)


小智 6

如果将来有人想这样做,您不需要下载任何东西(当然不是另一个答案建议的数百兆字节的 Windows 内容)。Ubuntu 附带的一个简单解决方案是xmag. Xmag 是 x11-apps 包的一部分,默认情况下应该已经安装。

这很简单。运行xmag,单击以选择屏幕的一个区域,然后在放大视图中按住鼠标按钮以查看精确的像素坐标。

xmag 的屏幕截图,无指针

您可以通过键入来阅读 xmag 手册man xmag


ish*_*ish 4

最合适的是...一个名为ColorPix的小型 Windows 工具(来自 WINE)

经过长时间和艰苦的搜索,似乎没有一个适用于 Ubuntu/Linux 的可用工具能够满足您的标准,即放大坐标显示

因此,我们选择了一个小型 Windows 工具——最重要的是——它只适用于默认的 WINE 安装,无需配置、安装、DLL 等。

  • 它具有可调节缩放、多种格式的一键复制和坐标显示等功能:

    在此输入图像描述

1.安装Wine

sudo apt-get install wine
Run Code Online (Sandbox Code Playgroud)

(就是这样!)

2.下载ColorPix

ColorPix可以在此处以小型、便携式 600KB exe 形式正式下载

我建议直接下载到本地二进制文件目录:

sudo wget -O/usr/local/bin/ColorPix.exe http://www.colorschemer.com/ColorPix.exe
Run Code Online (Sandbox Code Playgroud)

3. 创建 ColorPix 启动器

  • 我们先来获取一个图标:

    sudo wget -O/usr/share/icons/colorpix.png http://cdn.alternativeto.net/i/22e49edc-efa7-e011-979d-0025902c7e73_11865.png
    
    Run Code Online (Sandbox Code Playgroud)
  • 现在按Alt+F2并键入gksudo gedit /usr/share/applications/colorpix.desktop,然后粘贴以下内容并保存文件:

    [桌面入口]
    名称=ColorPix
    通用名称=ColorPix
    评论=ColorPicker 通过 WINE
    exec=wine /usr/local/bin/ColorPix.exe
    终端=假
    图标=/usr/share/icons/colorpix.png
    类型=应用
    启动通知=true
    
  • 从终端运行:

    sudo chmod +x /usr/share/applications/colorpix.desktop
    
    Run Code Online (Sandbox Code Playgroud)
  • 几秒钟后,它将在启动器中显示为:

    在此输入图像描述

4.使用ColorPix

启动它,第一次 WINE 初始化可能需要几秒钟。

下面的屏幕截图显示了它的运行情况,其中:

  • 上面的坐标
  • 下面不同格式的颜色值(点击复制到剪贴板)
  • 下方可调节放大镜
  • 到达所需像素后按任意键即可锁定值

    在此输入图像描述