Changing color of Bitmap label inside the code. - page 2

 
Fatemeh Ameri #:

Oh my god, It works, Thank you 1000 times.

great 


 
Lorentzos Roussos #:

What error did you get ?

If its an alpha channel ARGB bmp try this :

in your code 

 Also can we resize the bitmap image as well? I thought I could do that by changing the width/Height in ResourceCreate() function. but It does not work, if I only give a less width/Height to this function it will crop the image not make it smaller, if I give bigger  width/Height it won't show anything.

 
Fatemeh Ameri #:

 Also can we resize the bitmap image as well? I thought I could do that by changing the width/Height in ResourceCreate() function. but It does not work, if I only give a less width/Height to this function it will crop the image not make it smaller, if I give bigger  width/Height it won't show anything.

yeah , here is a code by Nikolai for that 

Forum on trading, automated trading systems and testing trading strategies

Scaling Bitmap

Nikolai Semko, 2018.06.07 09:20

Example of scaling. It is made in a hurry and errors are possible.

Canvas.mqh is slightly edited


 
Lorentzos Roussos #:

yeah , here is a code by Nikolai for that 


Seems like it is for MT5, you also got a file there" NewImageResizer.mq4 ". does that work as well?

 
Fatemeh Ameri #:

Seems like it is for MT5, you also got a file there" NewImageResizer.mq4 ". does that work as well?

Nikolai's is better , it's for both terminals the operations occur in the memory anyway.

 
Lorentzos Roussos #:

Nikolai's is better , it's for both terminals the operations occur in the memory anyway.

So should I convert Nikolai's code for MT4?
 
Fatemeh Ameri #:
So should I convert Nikolai's code for MT4?

yeah

 
Lorentzos Roussos #:

yeah

I tried Nikolai's code in MT5. It is constantly resizing the bitmap, I tried to turn that code to a function in which we give new size and it just shows the bitmap with new size, but does not work, when I call CImage Image(bmp,100,100,1); It does not show any thing in the chart, This is my code.
Maybe I should try to work with your own code.

void BmpChangeSize(string bmp,double x,double y,double transparency=1);
{
   CImage Image(bmp,100,100,1);
   Image.ResizeImage(300);
   Image.Finish();
}
I tried your code, again it seems to be working very well, well done  Lorentzos.
 
Fatemeh Ameri #:

I tried Nikolai's code in MT5. It is constantly resizing the bitmap, I tried to turn that code to a function in which we give new size and it just shows the bitmap with new size, but does not work, when I call CImage Image(bmp,100,100,1); It does not show any thing in the chart, This is my code.
Maybe I should try to work with your own code.

I tried your code, again it seems to be working very well, well done  Lorentzos.

hold on , i dug up some code 

bool the_shrinkist(uint &original_pixels[],
                   int  &original_width,
                   int  &original_height,
                   int  new_width,
                   int  new_height,
                   string resource_name){
bool shrink=false;
//step two : find steps for each axis
double x_step=((double)(original_width-1))/((double)(new_width-1));
double y_step=((double)(original_height-1))/((double)(new_height-1));
//step three : check and deploy the new array 
//buy if the shrink factor is 1 (meaning return to original ,then just copy the original
if(new_width==original_width&&new_height==original_height){
//turn new pixels into a resource 
  //ResourceFree(resource_name);
  bool to_resource=ResourceCreate(resource_name,original_pixels,original_width,original_height,0,0,original_width,COLOR_FORMAT_ARGB_NORMALIZE);
  if(to_resource){
  shrink=true;
  }else{Print("Shrinkist cannot create resource");}
}
else if(x_step>0.0&&y_step>0.0&&new_width>0&&new_height>0&&(new_width!=original_width||new_height!=original_height))
{
uint new_pixels[];
ArrayResize(new_pixels,new_width*new_height,0);
//loop into each new y pixel (NEW)
  //projected coordinates 
  double projected_x=0.0,projected_y=0.0;//represent a projection rectangle on the old image for each pixel  
  double max_x=original_width-1;
  double max_y=original_height-1;
  for(int y=0;y<new_height;y++)
  {
  projected_x=0.0;
  //loop into each new x pixel of that row (NEW)
    for(int x=0;x<new_width;x++)
    {
    //----Processing to "mix" the new smallest pixel as a composite of the projection on the original image
      //P0::start and end of each axis projected 
        double o_start_x=projected_x;
        double o_end_x=projected_x+x_step;
        double o_start_y=projected_y;
        double o_end_y=projected_y+y_step;
      //P1::steps for each axis on the original image 
        int o_steps_x=(int)(MathFloor(o_end_x)-MathFloor(o_start_x));
        int o_steps_y=(int)(MathFloor(o_end_y)-MathFloor(o_start_y));
      //P2::setup current projected coordinates for processing 
      //some steps may be redundant due to lack of sleep
        double pc_x=o_start_x;
        double pc_y=o_start_y;
      //P3::to deal with quads of pixels on the original each time we need a substep
        double o_substep_x=(o_end_x-o_start_x)/((double)o_steps_x);
        double o_substep_y=(o_end_y-o_start_y)/((double)o_steps_y);
      //P4+P5::Loop into the steps of y and to the steps of x
      //or loop into the steps of x for each step of y 
        //the summary floats 
          double total_area=0.0;
          double alpha_area_sum=0.0;
          double red_area_sum=0.0;
          double green_area_sum=0.0;
          double blue_area_sum=0.0;
          rctn_argb_color mixer_a1,mixer_a2,mixer_a3,mixer_a4;
        for(int ys=0;ys<o_steps_y;ys++)
        {
        if(pc_y>max_y){break;}
        pc_x=o_start_x;
        double thisYdecimals=pc_y-(MathFloor(pc_y));
        double nextY=pc_y+o_substep_y;
        if(nextY>max_y){nextY=max_y+0.99;}
        double nextYdecimals=nextY-(MathFloor(nextY));
         for(int xs=0;xs<o_steps_x;xs++)
          {
          if(pc_x>max_x){break;}
          //P6::sum of subpixels
            /*
            for each quad of subpixels (quad is the maximum possible amount of pixels used)
            calculate the amount contributed for all channels ,and sum the "areas"
            Each sub-projected-pixel has a decimal portion which can be used as a "score" or "amount" of "style" borrowed
            into the overall pixel.
            If we plot a grid with the projected pixels , and then map one quad pixel over it (or the area that the pixel of the smallest image
            is going to borrow color data from ,with the projected coordinates) we will find the following : 
            [rule 1] each projected pixels decimal will be used and notation .decimals for it
            [rule 2] thisX refers to this x coordinate 
            [rule 3] thisY refers to this y coordinate 
            [rule 4] nextX refers to this x coordinate + x substep (sub)
            [rule 5] nextY refers to this y coordinate + y substep (sub)
            
            so:
            area 1 = (1.0-thisX.decimals)*(1.0-thisY.decimals)
            area 2 = (nextX.decimals)*(1.0-thisY.decimals) 
            area 3 = (1.0-thisX.decimals)*(nextY.decimals)
            area 4 = (nextX.decimals)*(nextY.decimals)
            
            if the quad of pixels is 
            [A][B]
            [C][D] 
            then 
            area 1 gets from A
            area 2 gets from B
            area 3 gets from C
            area 4 gets from D
            
            theres also other possibilites that 
            the data is only using 1 or 2 pixels 
            and some calculations are redundant 
            but will deal with that later
            
            each area represents a "weight" in the returned pixel
            and ,if we sum all 4 areas we will get substep_x * substep_y which validates 
            this function . in theory
            
            */
            double thisXdecimals=pc_x-(MathFloor(pc_x));
            double nextX=pc_x+o_substep_x;
            if(nextX>max_x){nextX=max_x+0.99;}
            double nextXdecimals=nextX-(MathFloor(nextX));
            //calculate areas 
            double area_1=(1.0-thisXdecimals)*(1.0-thisYdecimals);
            double area_2=(nextXdecimals)*(1.0-thisYdecimals);
            double area_3=(1.0-thisXdecimals)*(nextYdecimals);
            double area_4=(nextXdecimals)*(nextYdecimals);
            /*
            get area colors
            */
            //area 1
            int pio_x=(int)MathFloor(pc_x);//pixel x in original
            int pio_y=(int)MathFloor(pc_y);//pixel y in original
            int pio_co=(original_width*pio_y)+pio_x;//mem slot in original
            mixer_a1.from_uint(original_pixels[pio_co]);
            //area 2
            pio_x=(int)MathFloor(nextX);//pixel x in original
            pio_co=(original_width*pio_y)+pio_x;//mem slot in original
            //error reporty
              if(pio_co>=ArraySize(original_pixels)){
              Print("area 2 error : pio x "+IntegerToString(pio_x)+" pio y "+IntegerToString(pio_y)+" pio_co "+IntegerToString(pio_co)+" of "+IntegerToString(ArraySize(original_pixels)));
              }
            mixer_a2.from_uint(original_pixels[pio_co]);    
            //area 3
            pio_x=(int)MathFloor(pc_x);
            pio_y=(int)MathFloor(nextY);
            mixer_a3.from_uint(original_pixels[pio_co]);
            //area 4
            pio_x=(int)MathFloor(nextX);
            mixer_a4.from_uint(original_pixels[pio_co]);
            //and mix them in 
            total_area+=area_1+area_2+area_3+area_4;
            red_area_sum+=(((double)mixer_a1.r)*area_1)+(((double)mixer_a2.r)*area_2)+(((double)mixer_a3.r)*area_3)+(((double)mixer_a4.r)*area_4);
            green_area_sum+=(((double)mixer_a1.g)*area_1)+(((double)mixer_a2.g)*area_2)+(((double)mixer_a3.g)*area_3)+(((double)mixer_a4.g)*area_4);            
            blue_area_sum+=(((double)mixer_a1.b)*area_1)+(((double)mixer_a2.b)*area_2)+(((double)mixer_a3.b)*area_3)+(((double)mixer_a4.b)*area_4);
            alpha_area_sum+=(((double)mixer_a1.a)*area_1)+(((double)mixer_a2.a)*area_2)+(((double)mixer_a3.a)*area_3)+(((double)mixer_a4.a)*area_4);
          pc_x+=o_substep_x;
          }
        pc_y+=o_substep_y;
        }
    //----Processing to "mix" the new smallest pixel as a composite of the projection on the original image ends here 
    //----the mix 
      //mem slot on new pixels array 
      int new_co=(new_width*y)+x;
      if(total_area>0.0){
      alpha_area_sum/=total_area;
      red_area_sum/=total_area;
      green_area_sum/=total_area;
      blue_area_sum/=total_area;
      if(alpha_area_sum>255.0){alpha_area_sum=255.0;}
      if(red_area_sum>255.0){red_area_sum=255.0;}
      if(green_area_sum>255.0){green_area_sum=255.0;}
      if(blue_area_sum>255.0){blue_area_sum=255.0;}
      mixer_a1.set(((uchar)alpha_area_sum),((uchar)red_area_sum),((uchar)green_area_sum),((uchar)blue_area_sum));
      mixer_a1.produce();
      new_pixels[new_co]=mixer_a1.co;
      }else{new_pixels[new_co]=0;}
    projected_x+=x_step;
    }
  projected_y+=y_step;
  //loop into each new x pixel of that row (NEW) ends here 
  }
//loop into each new y pixel (NEW) ends here 
//turn new pixels into a resource 
  bool to_resource=ResourceCreate(resource_name,new_pixels,new_width,new_height,0,0,new_width,COLOR_FORMAT_ARGB_NORMALIZE);
  if(to_resource){
  shrink=true;
  }else{Print("Shrinkist cannot create resource");}
}
//step three ends here 
return(shrink);
}
struct rctn_argb_color{
uchar a,r,g,b;//self explanatory
uint  co;//
rctn_argb_color(void){a=0;r=0;g=0;b=0;co=0;}
rctn_argb_color(uchar new_alpha,uchar new_red,uchar new_green,uchar new_blue){set(new_alpha,new_red,new_green,new_blue);}
void set(uchar new_alpha,uchar new_red,uchar new_green,uchar new_blue){a=new_alpha;r=new_red;g=new_green;b=new_blue;produce();}
uint produce(uchar from_alpha,uchar from_red,uchar from_green,uchar from_blue){
return(((from_alpha<<24)|(from_red<<16)|(from_green<<8)|(from_blue)));}
void produce(){co=produce(a,r,g,b);}
void from_uint(uint full_color){
uint transfer=full_color;transfer=transfer>>24;
a=(uchar)transfer;
transfer=full_color-(((uint)a)<<24);transfer=transfer>>16;
r=(uchar)transfer;
transfer=full_color-(((uint)a)<<24)-(((uint)r)<<16);transfer=transfer>>8;
g=(uchar)transfer;
transfer=full_color-(((uint)a)<<24)-(((uint)r)<<16)-(((uint)g)<<8);
b=(uchar)transfer;
co=full_color;
}
void save(int file_handle){
FileWriteInteger(file_handle,a,CHAR_VALUE);
FileWriteInteger(file_handle,r,CHAR_VALUE);
FileWriteInteger(file_handle,g,CHAR_VALUE);
FileWriteInteger(file_handle,b,CHAR_VALUE);
FileWriteInteger(file_handle,co,INT_VALUE);
}
void load(int file_handle){
a=(uchar)FileReadInteger(file_handle,CHAR_VALUE);
r=(uchar)FileReadInteger(file_handle,CHAR_VALUE);
g=(uchar)FileReadInteger(file_handle,CHAR_VALUE);
b=(uchar)FileReadInteger(file_handle,CHAR_VALUE);
co=(uint)FileReadInteger(file_handle,INT_VALUE);
}
};  
 
Lorentzos Roussos #:

hold on , i dug up some code 

What is the second piece of code? what is supposed to do?