Главная » Delphi » Графика » Иконка с затенением (выделенная, blend)

Иконка с затенением (выделенная, blend)

07:28
 
function BlendColor(val : TColor; blend : TColor; prc: integer=50):TColor;
var
   rv, gv, bv,
   rb, gb, bb,
   xv : byte;
   pv, pb : extended;
begin
   result := val;
   if (prc>100) or (prc<0) then exit;
 
   pb := prc/100;
   pv := 1-pb;
 
   rb := ((blend shr 16) and $FF);
   gb := ((blend shr 8) and $FF);
   bb := (blend and $FF);
 
   xv := ((val shr 24) and $FF);
   rv := ((val shr 16) and $FF);
   gv := ((val shr 8) and $FF);
   bv := (val and $FF);
 
   rv := Round((rb*pb)+(rv*pv));
   gv := Round((gb*pb)+(gv*pv));
   bv := Round((bb*pb)+(bv*pv));
 
   result := (xv shl 24) or
             (rv shl 16) or
             (gv shl 8) or
             bv;
end;
 
function DrawSelIcon(icon: HICON; size: word; canvas: TCanvas;x,y:integer; blend_prc: integer=50): boolean;
var
   pcolor, mcolor :TColor;
   _x, _y :integer;
  mask: TBitmap;
begin
  pcolor:=clNavy;
  DrawIconEx(Canvas.Handle, x, y, icon, size, size, 0, Canvas.Brush.Handle, DI_NORMAL);
  mask:=TBitmap.Create;
  try
    mask.PixelFormat := pf32bit;
    mask.Width := size;
    mask.Height := size;
    DrawIconEx(mask.Canvas.Handle, 0, 0, icon, size, size, 0, 0, DI_MASK);
    mcolor:=mask.Canvas.Brush.Color;
 
   for _x:=0 to size-1 do begin
     for _y:=0 to size-1 do begin
            if mask.Canvas.Pixels[_x,_y]<>mcolor then begin
               canvas.Pixels[x+_x,y+_y]:= BlendColor(canvas.Pixels[x+_x,y+_y], pcolor, blend_prc);
            end;
     end;
   end;
  finally
    mask.Free;
  end;
end;