reload image dynamically

Asked by Karl

I am updating images on the fly like this:

import shutil
image = "image.png"
click(image)
new_image = capture()
spot= getBundleFolder()+"image.png"
shutil.copyfile(new_image, spot)
click(spot)

Is there a way to reload/overwrite/clear an image in the cache:
[debug] Image: loaded: notFound.png (file:/C:/Users/User/Desktop/dynamicImage.sikuli/image.png)
[debug] Image: cached: notFound.png (524 KB) (# 1 KB 524 -- 0 % of 64 MB)
[debug] Image: reused: notFound.png (file:/C:/Users/User/Desktop/dynamicImage.sikuli/image.png)

I realize click(new_image) works, but I'm more interested in using a string for the click spot, but I need it versitile enough to use whatever strings can be used to define the parameters of click (i.e. Pattern("image.png").similar(0.37).targetOffset(50,50)
).

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

You might generally switch off image caching:
Settings.setImageCache(0)

this will stop caching and each image will be loaded again and again from file system.

Using later on
Settings.setImageCache(64)
will start caching again with the standard cache size of 64MB

To individually reload a cached image, you can say:
Image.reload("image.png")

If caching is switched off, reload() is a noop.

Revision history for this message
Karl (k-d) said :
#2

Thank you!