Simple bitmap cache question

How do I get a bitmap snapshot of a display object (e.g., cache of LabelLetters)? I don't want the original to be cached for the display, I just want a bitmap representation to work with separately.

let yourLablettersBitmapCache =new Bitmap(yourContName.cacheCanvas)
I'm not exactly sure, but maybe cacheCanvas is what you want.

Let labelLetters be in a container of your choice.

1 Like

Thanks @Ferudun - that put me in the right direction. Here's what worked:

displayObject.cache();
const bitmap = new Bitmap(displayObject.cacheCanvas);
displayObject.uncache();

I had to cache() it first. I uncache() it at the end because I don't want the original to operate like a bitmap. Note I'm doing this directly on the object (LabelLetters), not its container. Thanks again!

You're welcome I'm glad it worked.

You can pass any DisplayObject into a new Bitmap() and it will figure it out - so not need for the cacheCanvas.

const t = new LabelLetters().center()
new Bitmap(t).loc(100,100)

And did you two introduce yourselves in https://forum.zimjs.com/t/introductions-please-tell-us-something-about-you

1 Like