Image:drawImage with indexed image is black silhouette

Hi there,

I’m using drawImage to sort of copy an indexed image, but with a different canvas size, like this:

-- The source image is indexed. It's cropped (like all cels are)
local image = cel.image
-- The dest image is made the same size as the sprite (not cropped)
local dest = Image(sprite.width, sprite.height, image.colorMode)
-- Now draw the image into the destination
dest:drawImage(image, Point(cel.bounds.x, cel.bounds.y))

The destination image is a black silhouette and does not contain the correct palette.

What am I doing wrong?

Cheers,
Peter

Source:

Dest:

afaik, images don’t contain palettes. Sprites do. So if you are copying an image from one sprite and placing the copy in another sprite, then you have to copy the palette(s).

There is an off chance that a source sprite may have multiple palettes.

[Edit: The scripting API doesn’t give you a lot of tools to deal with that scenario, so unless you’re being thorough in making a script for use by others, it’s not worth worrying about.

If you want the two sprites to have different color modes: I’ve not checked if drawImage does a convert; usually I create an RGB image from the indexed image myself.]