What is the best way of using background images ? (flickering while resizing in DAW )

I am trying to use an image for background of my plugin . During debugging in VS2019 it is working properly but when i create it as a vst3 and try to run it in a DAW it is flickering when i try to resize it. Screen goes white during resizing.

This is my code in paint() section. I tried both Drawable and ımageCache, and it didn’t work.

Rectangle <float> frame(0, 0, getWidth(), getHeight()); 
/* background_image = Drawable::createFromImageData(BinaryData::P_svg, BinaryData::P_svgSize);// read the svg*/
pImage = ImageCache::getFromMemory(BinaryData::P_png, BinaryData::P_pngSize);
g.drawImage(pImage, frame);

and in resized() section

Rectangle<int> displayArea=Desktop::getInstance().getDisplays().getMainDisplay().userArea;
int displayborder = jmin(displayArea.getWidth(), displayArea.getHeight())-80;
setResizable(true,true); // window is resizeable
setResizeLimits(385, 800, displayborder, displayborder);
getConstrainer()->setFixedAspectRatio(385.0 / 800.0); // give a fixed ratio 

What is the best way to import images or drawables into a project? Which format should i use for best rendering performance and quality? what would you suggest?

This might not be the reason but you should load the image once, outside paint, cause here the image will be loaded from memory every time.

The poster is using ImageCache which would allocate and decode the image only the first time the paint() method is called. (It might still be a better idea to load the image outside the paint() method, though…)

1 Like

Ah, did not know, thanks for pointing out!

unfortunatelly it didn’t work. I tried to load it in constructor and also in header .Didn’t work. I use reaper to test them. Could it be about the way reaper handles resizeable windows? :confused:

I think the stuff you put in resized() doesn’t belong there. It is better placed in the constructor.
It could be, that setResizable() or touching the constrainer does weird things.

i moved that whole section into constructor but again it didn’t work :confused:

Two questions: do you attach an OpenGLContext?
That is a native window, in this case chances are you won’t be able to solve it.

Another problem might be, your other painting code that takes too long. Can you try to disable everything else except the image drawing, and see if the problem is still there?
I don’t think it is the drawImage itself, unless it is scaling a 4k image each time.
But I might be wrong…