Quote Originally Posted by Carlos Rocha View Post
I don't want to argue again about your vision of a global ImageList but I too would like to be able to create some kind of local one, even by using cCollection.
The point is that I would like to create independent UCs and be able to assign keys "1", "2",...
You can always use a local cCollection to hold cCairoSurface-References of course... as e.g. (under your own "local ImageKeys of choice"):
MyImgCol.Add Cairo.ImageList.AddImage("", PathToImage1), "1"
MyImgCol.Add Cairo.ImageList.AddImage("", PathToImage2), "2"

Quote Originally Posted by Carlos Rocha View Post
However, I can see that by using Cairo.Imagelist I have some advantages like the "automagically" detection of the image type. Implementing my own methods to distinguish between them would, at least, duplicate the necessary code. And certainly in a less efficient way.
Sure, the Cairo.ImageList.Addxxx-Functions offer a bit more functionality, compared to "direct, ImageLoading via Cairo.CreateSurface"...
The above 2 lines show already, how one can use the Cairo.ImageList as a "Surface-returning load-function" (via passing the ImageKey "" along)...
All the Cairo.ImageList.Addxxx-functions will return the just loaded Surface as a function-result ...
(and the always constant ""-empty ImageKey ensures, that ImageList-Contents do not "add up" in the global List)

Quote Originally Posted by Carlos Rocha View Post
So, my questions are:
How to solve potential collisions with image keys?
What's the best approach to detect the image type without relying on file extension (if using cCollection)?
I hope the above was answering your questions, although I still do not understand the need for "local ImageLists" entirely...

As for "context" (regarding "global ImageList vs. local ones"...

In my own Apps, I often use e.g. a ToolBar-Widget "multiple times" (e.g. in up-popping modal Dialogs which show a toolbar-control as well) -
and these toolbars and their different ToolBar-Buttons are fed (Icon-wise) from the global ImageList -
which makes sense, since this way they can share the same "globally cached" Icon-ImageSurface,
even if the multiple toolbars have different ToolBar-Buttons to show...
- e.g. ToolbarMain could show Buttons with ImageKeys: "Close, Open, Copy, Cut, Paste, Save, Help"
- and another ModalForm-ToolBar could e.g. just show Buttons: "Close, Save, Help"
Both ToolBar-Control-instances (their Button-Images) are nevertheless fed via the same global ImageListKeys -
though the Buttons sit at different "index-positions" within the ToolBar-instance in question of course...

In my ToolBar-Button-Click-Event-Routines, I'm not identifying them over the Index-Position of these Buttons though,
but instead use the ToobarButtonKey (which mostly is identical to the ImageKey-Name of the Buttons Icon) -
so I don't need "position-dependent Keys" like "1" or "2" - in case that's the problem on your end...

Perhaps describing in more detail, what you would do with "Control-local Images which have ImageKeys like "1", "2", etc. would clear things up for me.

HTH

Olaf