Converting Image Object to Screen Object

Asked by Nano Stray

I would like to capture a cutout from a captured screenshot and store it as png file:

  capturedImage = Screen.capture(Region(0,0,100,100))
  cutout = Region(30,30,50,50)
  Image(capturedImage).capture(cutout, "filename") #I do not want the capture to be based on the current screen but rather from capturedImage

Unfotunately, I get
[error] AttributeError ( 'Image' object has no attribute 'capture' )

I understand that it has to be a Screen object but I need the cutout to be from the capturedImage as the objects on the screen are moving fast

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Nano Stray
Solved:
Last query:
Last reply:
Revision history for this message
Nano Stray (nanostray) said :
#1
Revision history for this message
Nano Stray (nanostray) said (last edit ):
#2

I was very lucky to have found the answer by myself. I still don't know why this works but here's the solution:

You can convert Image variable to Buffered Image by using the .get() function

CUT_OUT_IMAGE= Image(CAPTURED_IMAGE).getSub(CUT_OUT_REGION) #This gives back an Image variable
BUFFERED_IMAGE= CUTOUT_iMAGE.get() #converts Image variable to Buffered Image

FILE_PATH= os.path.dirname(getBundlePath()) + "\\test.png" #this is a sikuli project directory
ImageIO.write(BUFFERED_IMAGE, "png", File(FILE_PATH)); #