用于轻松选择屏幕上的像素并获得颜色和绝对坐标的工具
我正在寻找一种工具,让我选择屏幕上的任何像素,并获得其RGB颜色和绝对(x,y)位置。
我在Windows上使用的工具显示了一个带有十字准线的大放大方块,让我可以轻松选择我想要的像素并获取其详细信息。
ubuntu有这样的东西吗?
最合适的是……一个名为ColorPix的微型Windows工具(通过WINE)
经过长时间的努力搜索,Ubuntu / Linux的可用工具似乎都不符合您的标准,即放大和坐标显示 。
因此,我们选择一个小型Windows工具 – 关键 – 只需使用默认的WINE安装,无需配置,安装,DLL等。
-
它具有可调节变焦,多种格式的一键复制和协调显示:
1.安装Wine
sudo apt-get install wine
(而已!)
2.下载ColorPix
ColorPix可以正式下载为一个小巧,便携的600KB exe文件
我建议直接下载到你当地的二进制文件目录:
sudo wget -O/usr/local/bin/ColorPix.exe http://www.colorschemer.com/ColorPix.exe
3.为ColorPix创建一个启动器
-
让我们先得到一个图标:
sudo wget -O/usr/share/icons/colorpix.png http://cdn.alternativeto.net/i/22e49edc-efa7-e011-979d-0025902c7e73_11865.png
-
现在按
Alt+F2
并键入gksudo gedit /usr/share/applications/colorpix.desktop
,然后粘贴以下内容并保存文件:[桌面入口] 名称= ColorPix GenericName = ColorPix 评论=通过WINE的ColorPicker Exec = wine /usr/local/bin/ColorPix.exe 终端=假 图标=在/ usr /共享/图标/ colorpix.png 类型=应用 StartupNotify您=真
-
从终端运行:
sudo chmod +x /usr/share/applications/colorpix.desktop
-
在几秒钟内,它将在启动器中可用:
4.使用ColorPix
启动它,并且在WINE初始化时第一次可能需要几秒钟。
下面的屏幕截图显示了它的实际效果,包括:
- 顶部的坐标
- 下面不同格式的颜色值(点击复制到剪贴板)
- 可调节放大镜如下
-
在所需像素上按任意键可锁定值
有一个名为gpick的工具。
在这里,您可以看到该工具的图像。 使用gpick,您可以选择像素,查看HTML代码,为调色板添加颜色并生成颜色。
这将为您提供我想要的东西。 不可否认,这是一个步骤,但它看起来比我显示每个小步骤更糟糕。
建立
安装ImageMagick和Shutter。
sudo apt-get install imagemagick shutter
如何获得x,y坐标和颜色
A.打开快门并单击选择按钮
B.请注意,当您移动鼠标时,它会显示您正在寻找的x,y坐标。
当你找到合适的位置时,用鼠标左键单击并绘制一个正方形来捕捉图像。 (只要你在感兴趣的像素上开始它(左上角),你的图像有多大并不重要。)
C.关闭快门中的图像
D.从终端运行以下命令。 这将为您提供左上角像素的颜色值。
convert ~/Pictures/Selection_001.png -crop 1x1+1+1 txt:- | sed -n 's/.* \(#.*\)/\1/p'
E.在命令行中继续并删除图像,以便下次快门拍照时,它会给出相同的名称。 (否则您需要在上一步骤(D)中调整名称。
rm ~/Pictures/Selection_001.png
将此代码粘贴到文本编辑器中,使其可执行并运行它。 使用吸管选择颜色时,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()
如果有人想在将来这样做,你不需要下载任何东西(当然不是数百兆字节的Windows内容,如另一个答案所示)。 Ubuntu附带的一个简单解决方案是xmag
。 Xmag是x11-apps软件包的一部分,默认情况下应该已经安装。
这很简单。 运行xmag
,单击以选择屏幕区域,然后在放大视图中按住鼠标按钮以查看精确的像素坐标。
您可以通过键入man xmag
来阅读xmag手册。
尝试imview ,它确实显示坐标。
您可以在此处下载其Doc页面和手册页 。