Seemingly Random Blinking GfxDrawImage Image

Is there something that might cause a graphic displayed by GfxDrawImage to blink?

Only two lines of code. It is most noticeable if I put it on 6-7 different charts with different symbols and then tile them (Window / Tile Horizontally). It is not a consistent blinking either - currently it is only a couple of the symbols that are blinking more than the others (every 5-10 seconds), but I have seen them all do it as I add/remove different bits of code in an attempt to troubleshoot.

Plot (Close, "Close", colorBlack, styleCandle);
GfxDrawImage ("C:\\Program Files\\AmiBroker\\Formulas\\Images\\Logo_Blue.png", 9, 18);

Is there anything that I can check that might cause this behavior? I'm sure it is something simple? It is driving me crazy.

Try replacing png files with a bmp files. A quote from: https://www.amibroker.com/guide/afl/gfxdrawimage.html :

Loading and drawing BMP files is much faster than PNG (as much as 10 times faster), approx load and rendering time is 0.3 ms for BMP, 3 ms for PNG (alphablended). Timings that you get from Code check and profile are misleading for Gfx functions because they don't include actual on-screen rendering.

I only use bmp files for displaying logos etc on the charts and have never experienced any blinking ...

Most image editing software can convert png file to a bitmap.

1 Like

thanks much @Milosz - that did it - I was hoping the use the transparency of the PNG at some point with some other stuff that I was doing but I'll settle for bmps for this if there is no blinking ...

1 Like

Post the video, or did not happen.

You should not get flickering no matter what speed you get because chart rendering is DOUBLE BUFFERED, so no matter what you do, it is flicker free. Speed does not have much to do with that.

I guess that true reason is elsewhere such as 3rd party software running on your computer (like antivirus) is blocking access (exclusively) to png files for example during "virus scan" so they can not be read from time to time.

FWIW: Alpha blending is a killer. To do alpha-blending for EACH pixel in the image you have to do 3 multiplications and 3 additions. So with 100x100 pixel you have 30000 multiplications and 30000 additions. Now if you do that 10 times per second for 10 charts you get 6000000 (6 million) calculations per second.

1 Like

[Edit: Gif is not showing as expecting; trying to fix that; Edit2: Used dropbox for video]

@Tomasz - Video (animated Gif) is above. Has not been sped up at all - that is what it looks like. If you want the original video I can email it to you.

Ami is running on a fresh install of Win10 - using the native 'Virus & Threat Protection' that Windows offers. The Amibroker system folder is listed in the exclusions and I tried turning the real-time protection on/off of the 'Virus & Threat Protection' but it made no difference.

The issue seems to be affected by the refresh of the charts. For instance using 0 in the Preferences/Intraday/Realtime chart refresh interval (which is what I use) makes the blinking more frequent (if of course during active market hours). Raising the number to 1 or higher slows down the instances of the blinking but does not remove the issue.

I have attached the test image below if you would like to test with it.

Test

It is not flickering. It is simply NOT drawing given image. As I wrote previously, it can be because the file is locked exclusively so it can not be open. PNG code path uses 3rd party library. Chances are that the library opens file exclusively and since you are trying to open very same file from multiple threads it fails if it tries to open twice at the same time.

Easy solution is to have SEPARATE FILE (different file name) for each chart, or use BMP because BMP code path is NOT using 3rd party library.

The word 'flickering' was not used in my inquiry.

Thanks @Tomasz for the explanation. BMP's will work for now. Knowing that separate files are required for PNGs is helpful.

I have tracked it down and indeed 3rd party library for PNGs is opening file exclusively. I will change that in the future but for now you can simply use different file names, or BMPs.

4 Likes

appreciated @Tomasz - thank you