Search code examples
sikulisikuli-idesikuli-x

How to save captured region as an image to a disk file?


I would like to be able to save a captured region to a png file on disk

The section of the code I have is:

r = Region(150,350,1700,630)
r.highlight(15)
screen = Screen()
image = screen.capture(r)

How to save now?

As mentioned in the documentation, tried to add a path and a name:

image = screen.capture(r, "/tmp", "aaa.png")

But returns an error:

[error] script [ finviz ] stopped with error in line 17
[error] TypeError ( capture(): expected 0-1 or 4 args; got 3 )
[error] --- Traceback --- error source first
line: module ( function ) statement 
17: main (  <module> )     image = screen.capture(r, "/tmp", "aaa.png")
[error] --- Traceback --- end --------------

Solution

  • There's this obscure statement in the documentation:

    (MUST be used as such undotted)

    which, when applied blindly...

    r = Region(150,350,1700,630)
    filename = capture(r, "/tmp", "aaa.png")
    

    ...makes it work !