Показать сообщение отдельно
  #8  
Старый 27.01.2013, 22:55
WVBR WVBR вне форума
Прохожий
 
Регистрация: 16.01.2013
Сообщения: 7
Репутация: 10
По умолчанию

NumLock благодарю

но всетаки решил проблему вот этим алгоритмом:

Код:
    procedure FillGradient(bt:tbitmap; ARect: TRect; StartColor, EndColor: TColor; StartAlpha, EndAlpha:byte; TopBottom:boolean);
    type TBitTArray = array[0..MaxInt div SizeOf(TRGBQuad)-1] of TRGBQuad;
    var
     rc1, rc2, gc1, gc2, bc1, bc2, ac1,ac2, _yy1,_yy2,y,x,_xx1,_xx2: Integer;
     rl1, rl2, gl1:integer; al:double;
     Brush: HBrush;  Row32:PRGBAArray; RowSet:TRGBQuad; RowSetP:^TRGBQuad;
     P: ^TBitTArray;
    begin
      rc1 := GetRValue(StartColor);
      gc1 := GetGValue(StartColor);
      bc1 := GetBValue(StartColor);
     
      rc2 := GetRValue(EndColor);
      gc2 := GetGValue(EndColor);
      bc2 := GetBValue(EndColor);
     
      if(ARect.Top<0) then ARect.Top:=0 else if(ARect.Top>bt.Height) then ARect.Top:=bt.Height;
      if(ARect.Left<0) then ARect.Left:=0 else if(ARect.Left>bt.Width) then ARect.Left:=bt.Width;
     
      _yy1:=0;
      _yy2:=ARect.Bottom-ARect.Top;
     
      _xx1:=0;
      _xx2:=ARect.Right-ARect.Left;
     
      if  TopBottom then begin
     
     
      for y:=_yy1 to _yy2-1 do begin
         Row32:= bt.ScanLine[y+ARect.Top];
     
         RowSet.rgbBlue:=(bc1 + (((bc2 - bc1) * (_yy1 + y)) div _yy2));
         Rowset.rgbGreen:=(gc1 + (((gc2 - gc1) * (_yy1 + y)) div _yy2));
         RowSet.rgbRed:=(rc1 + (((rc2 - rc1) * (_yy1 + y)) div _yy2));
     
         al:=((StartAlpha + (((EndAlpha - StartAlpha) * (_yy1 + y)) div _yy2)))/255;
     
         for x:=_xx1 to _xx2-1 do begin
            Row32[x+ARect.Left].rgbBlue:=round((1-al)*Row32[x+ARect.Left].rgbBlue+al*RowSet.rgbBlue);
            Row32[x+ARect.Left].rgbGreen:=round((1-al)*Row32[x+ARect.Left].rgbGreen+al*RowSet.rgbGreen);
            Row32[x+ARect.Left].rgbRed:=round((1-al)*Row32[x+ARect.Left].rgbRed+al*RowSet.rgbRed);
         end;
     
      end;
     
      end else begin
     
         P:=AllocMem(_xx2 * SizeOf(TRGBQuad));
         try
     
     
            RowSetP:=Pointer(@P^[0]);
            for x:=_xx1 to _xx2-1 do begin
                RowSetP.rgbRed:=(rc1 + (((rc2 - rc1) * (ARect.Left + x)) div ARect.Right));
                RowSetP.rgbGreen:=(gc1 + (((gc2 - gc1) * (ARect.Left + x)) div ARect.Right));
                RowSetP.rgbBlue:=(bc1 + (((bc2 - bc1) * (ARect.Left + x)) div ARect.Right));
                RowSetP.rgbReserved:=((StartAlpha + (((EndAlpha - StartAlpha) * (_xx1 + x)) div _xx2)));
                inc(RowSetP);
            end;
     
     
            for y:=_yy1 to _yy2-1 do begin
                Row32:= bt.ScanLine[y+ARect.Top];
     
                RowSetP:=Pointer(@P^[0]);
                for x:=_xx1 to _xx2-1 do begin
                    al:=RowSetP.rgbReserved/255;
     
                    Row32[x+ARect.Left].rgbBlue:=round((1-al)*Row32[x+ARect.Left].rgbBlue+al*RowSetP.rgbBlue);
                    Row32[x+ARect.Left].rgbGreen:=round((1-al)*Row32[x+ARect.Left].rgbGreen+al*RowSetP.rgbGreen);
                    Row32[x+ARect.Left].rgbRed:=round((1-al)*Row32[x+ARect.Left].rgbRed+al*RowSetP.rgbRed);
     
                    inc(RowSetP);
               end;
     
            end;
     
         finally
            FreeMem(P, _xx2*SizeOf(TRGBQuad));
         end;
     
     
      end;
    end;
Изображения
Тип файла: jpg Безымянный1.jpg (69.6 Кбайт, 18 просмотров)
Ответить с цитированием