【问题标题】:How do I take a screnshot using sikuli_cpython?如何使用 sikuli python 截屏?
【发布时间】:2015-06-30 00:52:14
【问题描述】:

我知道如何使用 Sikuli IDE 截屏。目前我正在使用sikuli_cpython。我也在尝试这样做:

import sikuli
my_screen = sikuli.DesktopScreenRegion()
my_capture = my_screen.capture()

print my_capture
<java.awt.image.BufferedImage at 0x66ef7b0 jclass=java/awt/image/BufferedImage jself=<LocalRef obj=0xbe79688 at 0x62fda00>>

这就是我不知道如何保存屏幕截图的地方。

dir(my_capture)
'BITMASK', 'OPAQUE', 'SCALE_AREA_AVERAGING', 'SCALE_DEFAULT', 'SCALE_FAST', 
'SCALE_REPLICATE', 'SCALE_SMOOTH', 'TRANSLUCENT', 'TYPE_3BYTE_BGR',     
'TYPE_4BYTE_ABGR', 'TYPE_4BYTE_ABGR_PRE', 'TYPE_BYTE_BINARY', 'TYPE_BYTE_GRAY',
'TYPE_BYTE_INDEXED', 'TYPE_CUSTOM', 'TYPE_INT_ARGB', 'TYPE_INT_ARGB_PRE',    
'TYPE_INT_BGR', 'TYPE_INT_RGB', 'TYPE_USHORT_555_RGB', 'TYPE_USHORT_565_RGB', 
'TYPE_USHORT_GRAY', 'UndefinedProperty', '__class__', '__cls_storage', '__delattr__', 
'__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', 
'__javaclass__', '__javaconstructor__', '__module__', '__new__', '__pyx_vtable__', 
'__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', 
'__subclasshook__', '__weakref__', 'addTileObserver', 'coerceData', 'copyData', 
'createGraphics', 'equals', 'flush', 'getAccelerationPriority', 'getAlphaRaster', 
'getCapabilities', 'getClass', 'getColorModel', 'getData', 'getGraphics', 'getHeight', 
'getMinTileX', 'getMinTileY', 'getMinX', 'getMinY', 'getNumXTiles', 'getNumYTiles', 
'getProperty', 'getPropertyNames', 'getRGB', 'getRaster', 'getSampleModel', 
'getScaledInstance', 'getSource', 'getSources', 'getSubimage', 'getTile', 
'getTileGridXOffset', 'getTileGridYOffset', 'getTileHeight', 'getTileWidth', 
'getTransparency', 'getType', 'getWidth', 'getWritableTile', 'getWritableTileIndices', 
'hasTileWriters', 'hashCode', 'isAlphaPremultiplied', 'isTileWritable', 'notify', 
'notifyAll', 'releaseWritableTile', 'removeTileObserver', 'setAccelerationPriority', 
'setData', 'setRGB', 'toString', 'wait']

【问题讨论】:

  • 你能告诉我 dir(my_capture) 的结果吗?
  • 只有sikuli_script.py,就是包含我提到的代码的脚本。
  • 不。我的意思是检查 my_capture 的属性。 dir() 是 Python 中的内置函数。
  • 我已经用 dir(my_capture) 的输出更新了我的问题。
  • 好像没有api让你把它存储为图片文件...

标签: python sikuli


【解决方案1】:

使用以下内容(假设 sikuli 是使用文档中的通配符导入的):

img = Screen().capture()
filePath = os.path.join(r"c:\path\to\place\image", "imageOutput.png")
shutil.move(img, filePath)
print "File is now locatede at %s" % filePath

到目前为止,您已经拥有图像,但您需要将图像从保存位置移动到您选择的位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-14
    • 2021-06-28
    • 1970-01-01
    • 2012-08-22
    • 2014-05-10
    • 2022-06-17
    • 2020-06-14
    • 2014-08-23
    相关资源
    最近更新 更多