Question: why this don’t work (as I expect) if the last line is commented?
Question: why this don’t work (as I expect) if the last line is commented? Maybe when you set an icon it is set a copy instead?
var e=LL.getEvent();
var it=e.getItem();
//get default icon
var imagen=it.getDefaultIcon();
var bmp_orig = imagen.getBitmap();
//a copy of the icon
var img = LL.createImage(bmp_orig.getWidth(), bmp_orig.getHeight());
img.draw().drawBitmap(bmp_orig, 0, 0, null);
img.update();
//set custom icon
it.setCustomIcon(img);
//paint bitmap
var bit=img.getBitmap();
bit.eraseColor(0xFFFFFFFF);
//dont work
//paint canvas
img.draw().drawColor(0xFF000000);
//dont work too
//save/update
img.update();
img.save();
//uncomment and it will work
//it.setCustomIcon(img);
]]>
< ![CDATA[
Definitely! That’s the only explanation.
]]>
< ![CDATA[
Now I know this, all makes sense…I was going crazy!
Because if you use getCustomIcon() and then you modify it, it is modified.
That’s why I thought setIcon will keep the reference…but it seems don’t.
]]>
< ![CDATA[
maybe Pierre Hébert can explain in the api doc how things work in more detail.
]]>
< ![CDATA[
Definitely it sets a copy, the alert shows two different images.
var e=LL.getEvent();
var it=e.getItem();
//get default icon
var img=it.getDefaultIcon();
it.setCustomIcon(img);
var img2=it.getCustomIcon();
alert(img+”\n”+img2);
]]>
< ![CDATA[
This was a problem for me too.
Javascript has not really something like references, but Java does. Because we use both it’s really hard to determine wether a reference or a copy is used.
]]>
< ![CDATA[
I notice you can’t use functions where a parameter is used by reference, in bitmap.getPixels(array,…) it’s supposed to retrieve the pixels in ‘array’, however it don’t work because of references.
(Fortunately in this case getPixel does work)
]]>
< ![CDATA[
Indeed, the image given for the custom (or default) icon is not kept as a reference.
The subtle reason is that the icon might not be used as is. Depending on the configuration, the “raw” icon may be extended with a shadow, or scaled, or filtered or layers can be added too.
As a consequence the base icon image is never kept: it is loaded, used to create the final image, then dropped from memory. If nothing has to be done then this will be a direct copy, but this is not always true and for this reason icon images are never shared. Modifying an image obtained from getCustomIcon should not result in visible change when calling update(), but only when calling save() because the item is fully reloaded and its image is recreated from its icon), unlike getImage() which return the final image in memory.
]]>