如何使用sikuli python截取屏幕截图?

时间:2014-09-25 02:05:06

标签: python sikuli

我知道如何使用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']

1 个答案:

答案 0 :(得分:0)

使用以下内容(假设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

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