The function reads data from the graphical resource created by ResourceCreate() function or saved in EX5 file during compilation.

bool  ResourceReadImage(
   const string      resource_name,       // graphical resource name for reading
   uint&             data[],              // array for receiving data from the resource
   uint&             width,               // for receiving the image width in the resource
   uint&             height,              // for receiving the image height in the resource



[in]  Name of the graphical resource containing an image. To gain access to its own resources, the name is used in brief form "::resourcename". If we download a resource from a compiled EX5 file, the full name should be used with the path relative to MQL5 directory, file and resource names – "path\\filename.ex5::resourcename".


[in]  One- or two-dimensional array for receiving data from the graphical resource.


[out]  Graphical resource image width in pixels.


[out]  Graphical resource image height in pixels.

Return Value

true if successful, otherwise false. To get information about the error, call the GetLastError() function.


If data[] array is then to be used for creating a graphical resource, COLOR_FORMAT_ARGB_NORMALIZE or COLOR_FORMAT_XRGB_NOALPHA color formats should be used.

If data[] array is two-dimensional and its second dimension is less than X(width) graphical resource size, ResourceReadImage() function returns false and reading is not performed. But if the resource exists, actual image size is returned to width and height parameters. This will allow making another attempt to receive data from the resource.


//| Script program start function                                    |
void OnStart()
//--- declare the parameters of the graphical resource
   string rc_name="Resource";
   uint   rc_width=100;
   uint   rc_height=100;
   uint   rc_data[];
   uint   rc_size=rc_width*rc_height;
//--- set the size of the pixel array
      Print("ArrayResize() failed. Error code: ",GetLastError());
//--- fill the pixel array with a transparent color and create a graphical resource based on it
      Print("ResourceCreate() failed. Error code: ",GetLastError());
   Print("Size of created recource array: ",rc_data.Size());
//--- check the created graphical resource.
//--- get the time and price data of the current bar
   MqlTick tick={};
      Print("SymbolInfoTick() failed. Error code: ",GetLastError());
//--- create the Bitmap object using the coordinates of the last tick price and time
   string obj_name="Bitmap";
      Print("ObjectCreate() failed. Error code: ",GetLastError());
//--- set the width and height of the created bitmap object equal to the width and height of the graphical resource.
//--- set the object anchor point to its center.
//--- specify the previously created graphical resource for the bitmap object as an image file
//--- In this case, in order to indicate the name of the graphical resource used, we need to add "::" before its name
//--- set the DodgerBlue color with the transparency of 200
   uint clr=ColorToARGB(clrDodgerBlue,200);
//--- fill the entire array of pixels of the graphical resource with the set color
//--- update the graphical resource data
//--- wait 3 seconds before reading the graphical resource data 
   Print("Wait 3 seconds before ResourceReadImage()");
//--- read the image from the resource into a new array of pixels
   uint rc_data_copy[];
   uint w=0,h=0;
      Print("ResourceReadImage() failed. Error code: ",GetLastError());
//--- set the OrangeRed color with the transparency of 200
//--- fill the entire array of pixels of the graphical resource with the set color and create a new graphical resource based on it
      Print("New ResourceCreate() failed. Error code: ",GetLastError());
   Print("Size of created new recource array: ",rc_data_copy.Size());
//--- create the "Graphical label" object using the coordinates of the last tick price and time
   string obj_name2="BitmapLabel";
      Print("ObjectCreate() failed. Error code: ",GetLastError());
//--- get screen coordinates using the previously received price and time
   int x=0,y=0;
      Print("New ChartTimePriceToXY() failed. Error code: ",GetLastError());
//--- set the width and height of the created graphical label object equal to the width and height of the graphical resource.
//--- set the object anchor point to its center.
//--- set the copied graphical resource as an image file for the graphical label object
//--- in this case, in order to indicate the name of the graphical resource used, we need to add "::" before its name
//--- change the color of the new graphical label object
   Print("Wait 3 seconds before changing color to GreenYellow");
//--- set the GreenYellow color with the transparency of 200
//--- fill the entire array of pixels of the new graphical resource with the set color
//--- update the graphical resource data 
//--- wait three seconds and delete resources and both objects
   Print("Wait 3 seconds before deleting both objects");
   Print("Deleting Resource and all Bitmap objects");
//| Update graphical resource data                                   |
void Update(const string res_name,const uint &pixel_data[],const uint width,const uint height,const bool redraw)
//--- leave if zero dimensions are passed
   if(width==0 || height==0)
//--- update resource data and redraw the chart
   if(ResourceCreate(res_name,pixel_data,width,height,0,0,0,COLOR_FORMAT_ARGB_NORMALIZE) && redraw)

See also

Resource, ObjectCreate(), ObjectSetString(), OBJPROP_BMPFILE