100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > c语言 获取 屏幕 像素坐标和颜色 在屏幕上获取颜色和绝对坐标 方便地选择像素...

c语言 获取 屏幕 像素坐标和颜色 在屏幕上获取颜色和绝对坐标 方便地选择像素...

时间:2019-07-09 23:58:24

相关推荐

c语言 获取 屏幕 像素坐标和颜色 在屏幕上获取颜色和绝对坐标 方便地选择像素...

问题

我寻找一个工具,可以让我选择屏幕上的像素,并获得RGB颜色和绝对(x,y)的位置。

ubuntu有没有什么类似的东西?

答案1

最合适的是,一个Windows的小工具ColorPix (通过wine )

我经过长时间艰苦的搜索,Ubuntu/Linux的工具都不能满足你的条件,放大和坐标显示。

我们需要一个很小的Windows工具--非常关键--它适用于默认的WINE安装,没有配置、安装、 DLL等等

它有可调整的缩放,一键复制多种格式和坐标显示:

1.安装winesudo apt-get install wine

2.下载ColorPix

ColorPix 可以下载便携版 600KB >> 这里

我建议使用以下方法直接下载到本地二进制文件目录中:sudo wget -O/usr/local/bin/ColorPix.exe /ColorPix.exe

3.为ColorPix创建启动器

先得到一个图标:sudo wget -O/usr/share/icons/colorpix.png /i/22e49edc-efa7-e011-979d-0025902c7e73_11865.png

按Alt+F2现在并键入gksudo gedit /usr/share/applications/colorpix.desktop 粘贴以下文件并保存文件:[Desktop En试试]

Name=ColorPix

GenericName=ColorPix

Comment=ColorPicker via WINE

Exec=wine /usr/local/bin/ColorPix.exe

Terminal=false

Icon=/usr/share/icons/colorpix.png

Type=Application

StartupNotify=true

从终端运行:sudo chmod +x /usr/share/applications/colorpix.desktop

4.使用ColorPix

启动它,第一次在wine初始化时需要几秒钟。

下面的屏幕截图显示了它的实际效果,包括:顶部的坐标

以下不同格式的颜色值(单击可复制到剪贴板)

下方可调放大镜

按下任意键一旦对你想要的像素锁定值

答案2

有一个叫做gpick。

使用gpick可以选择像素,请参见HTML代码,将颜色添加到调色板并生成颜色。

答案3

安装程序

安装ImageMagick &Shutter。sudo apt-get install imagemagick shutter

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

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

注意,当移动鼠标时,它会显示你寻找的x,y坐标。

当你有了正确的位置,继续点击鼠标按钮,画一个方块来捕捉图像。图像的大小实际上并不重要,只要在感兴趣的像素上启动(左上角),

C.在Shutter中关闭图像

D.从终端运行以下命令,这会给出左上角像素的颜色值。convert ~/Pictures/Selection_001.png -crop 1x1+1+1 txt:- | sed -n 's/.* (#.*)/1/p'

E.在命令行中,继续删除图像,以便下次Shutter拍照时,它赋予它相同的名称,否则,你需要在上一步中调整名称(D)。rm ~/Pictures/Selection_001.png

答案4

将此代码粘贴到文本编辑器中,使它可执行并运行,使用滴管选择颜色时,x和y坐标将出现在顶部。#!/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()

答案5

Ubuntu附带的一个简单解决方案是xmag,Xmag是x11-apps包的一部分,默认情况下应该已经安装。

运行xmag,点击选择屏幕的某个区域,然后按住放大视图中的鼠标按钮,查看精确的像素坐标。

可以通过键入以下命令阅读xmag手册。

答案6

试试imview

相关文章

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。