Kodi Community Forum

Full Version: Cache images so that HD doesn't spin up
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hello. over the past week i've started looking at how to modify an existing xbmc script so that it will cache images rather than having to spin up the hd when it needs to display a controlimage.

this is the original bit of script to put the image on the screen:

Quote:self.frame = xbmcgui.controlimage(w - 359, h - 138, 77, 103, 'someimage.jpg')
self.addcontrol(self.frame)

the way i thought i could achieve the cache is to stick the controlimage into an array, and pull it out of the array (which i assumed would be in memory) to write it to the screen, e.g.

Quote:preloadedimages = {} # used to pre-load images

def cacheimage(x, y, w, h, the_filename):
global preloadedimages
preloadedimages[the_filename] = xbmcgui.controlimage(x, y, w, h, scriptfolder + the_filename)

def cacheimages(w, h):
cacheimage(w - 282, h - 138, 222, 103, imagedialog)

def cachedimage(the_filename):
global preloadedimages
return preloadedimages[the_filename]

class initialise(xbmcgui.windowdialog):
def (self):
w = self.getwidth()
h = self.getheight()
cacheimages(w, h)

class main(xbmcgui.windowdialog):
def (self):
self.bg = cachedimage(imagedialog)
self.addcontrol(self.bg)

despite all this, when it adds the control to the screen the hard drive will spin up. is this a limitation with controlimages? or is there a technique to make cached images work?

many thanks in advance,

matt.
caching the way you expect is not supported.

how many images do you need. can you use an array for your images. i did this in poker timer ii for the clock display. they are small images though.
oh cool, i'll download a copy of your script and take a look. thanks for the heads up.

i'm not caching too many images; probably around 5, plus the ability for a user to add their own. most are 77x77 pixels. i'll watch out because i don't want the xbox to start running out of memory just when this script is running.
that many at that size won't be a problem.
is there a way to pass a proccessed image using PIL to a xbmc image object without first saving the file