Including bitmap resources inside ex4 file

 

Hello,


I create a UI panel for my expert advisor and it uses the #resource keyword to import it in.

I thought this was all that is needed, but when I compile my expert advisor, it doesn't embed the bitmap inside the ex4 file. It still complains that it cannot find the file when I put it on my VPS and don't copy the original bmp file meaning it has not embed the bitmap inside the ex4 file.


I'm using this:

#resource "//Images//background.bmp"


and then using this to display it:

 if(!ObjectCreate(chart_ID,name,OBJ_BITMAP_LABEL,sub_window,0,0))

     {

      Print(__FUNCTION__,

            ": failed to create \"Bitmap Label\" object! Error code = ",GetLastError());

      return(true);

     }

//--- set the images for On and Off modes

   if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,0, "//Images//background.bmp" ))

     {

      Print(__FUNCTION__,

            ": failed to load the image for On mode! Error code = ",GetLastError());

      return(true);

     }



It displays the error:  failed to load the image for On mode! Error code = 5020


Why does this not work without actually making a directory called images and copying the image there?

 
agentx64:

Hello,


I create a UI panel for my expert advisor and it uses the #resource keyword to import it in.

I thought this was all that is needed, but when I compile my expert advisor, it doesn't embed the bitmap inside the ex4 file. It still complains that it cannot find the file when I put it on my VPS and don't copy the original bmp file meaning it has not embed the bitmap inside the ex4 file.


I'm using this:

#resource "//Images//background.bmp"


and then using this to display it:

 if(!ObjectCreate(chart_ID,name,OBJ_BITMAP_LABEL,sub_window,0,0))

     {

      Print(__FUNCTION__,

            ": failed to create \"Bitmap Label\" object! Error code = ",GetLastError());

      return(true);

     }

//--- set the images for On and Off modes

   if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,0, "//Images//background.bmp" ))

     {

      Print(__FUNCTION__,

            ": failed to load the image for On mode! Error code = ",GetLastError());

      return(true);

     }



It displays the error:  failed to load the image for On mode! Error code = 5020


Why does this not work without actually making a directory called images and copying the image there?

#resource "//Images//background.bmp" ?

see: https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_bitmap

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_BITMAP
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_BITMAP
  • www.mql5.com
OBJ_BITMAP - Object Types - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Roberto Jacobs #:

#resource "//Images//background.bmp" ?

see: https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_bitmap

https://www.mql5.com/en/docs/runtime/resources

The #resource command tells the compiler that the resource at the specified path path_to_resource_file should be included into the executable EX5 file. Thus all the necessary images and sounds can be located directly in an EX5 file, so that there is no need to transfer separately the files used in it, if you want to run the program on a different terminal. Any EX5 file can contain resources, and any EX5 program can use resources from another EX5 program.

The files in format BMP and WAV are automatically compressed before including them to an EX5 file. This denotes that in addition to the creation of complete programs in MQL5, using resources also allows to reduce the total size of necessary files when using graphics and sounds, as compared to the usual way of MQL5 program writing.

The resource file size must not exceed 128 Mb.



Except for my MT4 expert advisor is not packing them into the EX4 file using #resource.

#resource "\\Experts\\Advisors\\bla\\blalogo.bmp";

Documentation on MQL5: MQL5 programs / Resources
Documentation on MQL5: MQL5 programs / Resources
  • www.mql5.com
Resources - MQL5 programs - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
agentx64 #:

https://www.mql5.com/en/docs/runtime/resources

The #resource command tells the compiler that the resource at the specified path path_to_resource_file should be included into the executable EX5 file. Thus all the necessary images and sounds can be located directly in an EX5 file, so that there is no need to transfer separately the files used in it, if you want to run the program on a different terminal. Any EX5 file can contain resources, and any EX5 program can use resources from another EX5 program.

The files in format BMP and WAV are automatically compressed before including them to an EX5 file. This denotes that in addition to the creation of complete programs in MQL5, using resources also allows to reduce the total size of necessary files when using graphics and sounds, as compared to the usual way of MQL5 program writing.

The resource file size must not exceed 128 Mb.



Except for my MT4 expert advisor is not packing them into the EX4 file using #resource.

#resource "\\Experts\\Advisors\\bla\\blalogo.bmp";

I think I figured it out. I need to use  :: before the resource name when using CreateObject.

 
agentx64 #:

I think I figured it out. I need to use  :: before the resource name when using CreateObject.

yep.