Color Transparency

 

Hello friends,

does anyone have any simple example of how to use transparency

I tried to use an example here on the site, but I couldn't.


Thank you very much in advance.


Cláudio.

 
https://www.mql5.com/en/articles/1341
Studying the CCanvas Class. How to Draw Transparent Objects
Studying the CCanvas Class. How to Draw Transparent Objects
  • www.mql5.com
Drawing in MetaTrader 5 is simple and you need to know only a few nuances. One of the nuances is how the terminal screen is designed. More precisely, we are interested in the way the graphics are output on the screen. For example, a chart can be displayed in the foreground or in the background. Color output on the screen will depend on the...
 
Cláudio Müller:

Hello friends,

does anyone have any simple example of how to use transparency

I tried to use an example here on the site, but I couldn't.


Thank you very much in advance.


Cláudio.

string system_tag="CanvasTests_";
int OnInit()
  {
  ObjectsDeleteAll(0,system_tag);
  uint img[];
  uint width=200,height=300;
  color testcolor=clrDodgerBlue;
  uchar testopacity=128;//Opacity Varies between 0 and 255 . 0 means 100% transparent , 255 means 0% transparent
  uint tc=ColorToARGB(testcolor,testopacity);
  //total image data width*height
  ArrayResize(img,width*height,0);
  ArrayFill(img,0,width*height,tc);//fill image data with color <<test color>> at opacity <<testopacity>>
  string resource_name="TestResource";//resource is the image data turned into a bitmap
  ResourceFree(resource_name);
  bool cre=ResourceCreate(resource_name,img,width,height,0,0,width,COLOR_FORMAT_ARGB_NORMALIZE);
  if(!cre) Alert("Cant Create Resource");
  if(cre)
    {
    //create the output object - or the receptor of the resource 
    bool co=ObjectCreate(0,system_tag+"_screen",OBJ_BITMAP_LABEL,0,0,0);
    if(!co) Alert("Cant Create Bitmap Object");
    if(co)
      {
      //size the receptor , ! if the image data is smaller than the display size , nothing will be displayed !
      //                    ! if the image data is >= than the display size , display will be based on the bitmap offsets !
      ObjectSetInteger(0,system_tag+"_screen",OBJPROP_XSIZE,width);
      ObjectSetInteger(0,system_tag+"_screen",OBJPROP_YSIZE,height);
      ObjectSetInteger(0,system_tag+"_screen",OBJPROP_XDISTANCE,0);//position x in screen
      ObjectSetInteger(0,system_tag+"_screen",OBJPROP_YDISTANCE,0);//position y in screen
      /* Link the Bitmap object with that resource.
         Everytime you make a change to the img array and  
         recreate the resource (with the same name) all objects
         bound to it will refresh when you call ChartRedraw -or when chart redraws
      */
      ObjectSetString(0,system_tag+"_screen",OBJPROP_BMPFILE,"::"+resource_name);
      /* if you need to quickly show/hide a bitmap use :
      ObjectSetInteger(0,system_tag+"_screen",OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);//Hides
      ObjectSetInteger(0,system_tag+"_screen",OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);//Shows
      */
      }
    }
  ArrayFree(img);
  return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  ObjectsDeleteAll(0,system_tag);
   
  }
 
Cláudio Müller:

Hello friends,

does anyone have any simple example of how to use transparency

I tried to use an example here on the site, but I couldn't.

Thank you very much in advance.

Cláudio.


Reason: