bufferedImage removed?


#1

Hi,

I have only just started using this library a few months ago - I started with the older pre 2.0 version that provided direct access to a component’s bufferedImage. I used this bufferedImage to be able to draw directly onto the buffer without triggering an immediate refresh/redraw . Here is the code that breaks under the new 2.0 version:

void MyComponent::MyCreateSnapshot(Image** img, int x, int y, int w, int h) { if(bufferedImage != NULL && w > 0 && h > 0) { if(*img != NULL) { deleteAndZero(*img); } *img = new Image(flags.opaqueFlag ? Image::RGB : Image::ARGB, w, h, true); Graphics imageContext(**img); imageContext.setOrigin (-x, -y); imageContext.drawImageAt(bufferedImage, 0, 0); } }

I’m at a bit of a loss to do the same thing under the new 2.0 version as the bufferedImage has been removed from the base component class. I noticed that a CachedImage class has been added though. Is the CachedImage supposed to serve as a replacement for the bufferedImage?
I’ve experimented with createComponentSnapshot but that triggers a redraw and really breaks a lot of my code.

Is there a simple way to do this? Do I need to override CachedImage with my own use case?


#2

Yes - CachedImage is a far more powerful tool for doing this kind of thing. Your old code looks like a real hack, it’s probably not a bad thing to rewrite it!


#3

Thanks for the quick reply Jules. That’s what I thought (cough… feared).
Is there an example of using CachedImage with a component class anywhere?


#4

Other people might have examples… I’ve used it internally for various things if you grep for it.