ResourceCreate() function can replace #resource

 

Hi guys

If I call ResourceCreate() function inside another function, it will include bmp file into ex5?

It can be used instead of  #resource  command? 

Anyone can share an example how to use  ResourceCreate().

Thanks

 
/* Example using Resource Functions 
   Create a smaller image from a larger image */

#resource  "\\Images\\icons.bmp"
/*//OR
  const string myIcons = "Images\\icons.bmp"; //icons resource name
  ResourceCreate(  myIcons, "\\Images\\icons.bmp");//Create icons image resource
*/
const string myIcons = "::Images\\icons.bmp"; //icons resource name
const string newIcon = "Files\\icons_small_new.bmp"; //new resource name


uint data[];    //array to store image data
int imageW = 0; //variable to store image data width
int imageH = 0; //variable to store image height

ResourceReadImage( myIcons, data, imageW, imageH ); //Read Image Data;

ResourceCreate( newIcon, data, 40, 40, 15 , 15 , imageW, COLOR_FORMAT_ARGB_NORMALIZE ); //Create a new smaller image

ResourceSave( newIcon,"icons_small_new.bmp" );  //Save the image to file 


//ObjectSetString( 0, bitmap_name, OBJPROP_BMPFILE, 0, "::" + newIcon ); // example use of resource( file must exist first to be used as a bitmap image resource )

//---clean up, usually at end of program
//ResourceFree( newIcon ); 
//ResourceFree( myIcons );


The above is example that creates a small( 40px * 40px ) image from a larger( 1008px * 1008px  )image :

- ResourceReadImage is used to read image data from an already imported image( either by #resource OR using ResourceCreate )

- ResourceCreate is used to create the smaller image from the image data array( the second variation of the function is used here see documentation here )

  data_width is the width of the original image( setting the wrong value here may not produce an image )

- ResourceSave saves the created resource to file( the path is relative to "Files" folder )

- ResourceFree deletes dynamically created resource after you are done with it 

Screenshot of results


Hope this helps

ResourceCreate - Common Functions - MQL4 Reference
ResourceCreate - Common Functions - MQL4 Reference
  • docs.mql4.com
ResourceCreate - Common Functions - MQL4 Reference
Files:
icons.zip  67 kb
 
David Gitau Gakunga #:


The above is example that creates a small( 40px * 40px ) image from a larger( 1008px * 1008px  )image :

- ResourceReadImage is used to read image data from an already imported image( either by #resource OR using ResourceCreate )

- ResourceCreate is used to create the smaller image from the image data array( the second variation of the function is used here see documentation here )

  data_width is the width of the original image( setting the wrong value here may not produce an image )

- ResourceSave saves the created resource to file( the path is relative to "Files" folder )

- ResourceFree deletes dynamically created resource after you are done with it 



Hope this helps

Hi you. Can we also change the color of the new resource? how?