Image not loading with GfxDrawImage

Hello Experts,

I am trying to load an image on to the Chart Window with GfxDrawImage, the code is getting complied with 0 errors but the image is not visible on the screen.

Code:

_SECTION_BEGIN("Price");

SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

image = "F:\\Icons\\bear.bmp";
GfxSetZOrder(1);
GfxDrawImage(image,100,0);

_SECTION_END();

Screenshot_1

Please help me with the solution.

Thanks in Advance,
Prasad

@prasadaraokarri , your code seems correct (I tested it with AmiBroker 6.31 64-bit)

Please, check that the file path/filename is correct/corresponding and in such a case, try another small .bmp file (ideally generated from a different source).
Additionally, verify that you have the permissions to read data from the selected folder; is that folder local or a network resource?

1 Like

Thank you @beppe for the reply.

The file path is correct and yes i have the permissions to read data from the selected folder, It is local folder.

I even tried with small .bmp file, it is same with that too ( didn't load ).

@prasadaraokarri, in this case, for lack of better ideas, even though it may seem overwhelming, I would try using an utility like ProcessMonitor to monitor file access and try to figure out what happens.

First run the code in AFL Editor - it should tell you if file is missing.
If file is not missing, it might be that the file you are trying to use is incompatible with Windows API ::LoadImage.
You should try .PNG file

1 Like

Thank you @Tomasz,

Yes sir, I think the file I am using is incompatible with Windows API::Loadimage.

I tried with .PNG file and it worked perfectly sir.

According to StackOverflow here: c++ - (Bitmap)LoadImage() returns NULL and GetLastError() returns 0 - Stack Overflow
Windows ::LoadImage does not like BMPs created with GIMP program. Recommended solution is to open offending BMP in Windows PAINT program, make some change and save it back from Paint program. This should save the file in accepted format.

1 Like

Thank you @Tomasz,

Yeah, i have opened the file in PAINT and made small change and saved it as .bmp, and it really worked.

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

image = "F:\\Icons\\Bear_Bit.bmp";
GfxSetZOrder(1);
GfxDrawImage(image,100,100);

_SECTION_END();

Bitmap

I once again thank you for the solution sir.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.