[TRUCO DELPHI] Cambiar los canales de Colores de un TBitmap.
delphi
function SetRGBChannelValue(Bitmap: TBitmap; Red, Green, Blue: Integer): Boolean; var i, j: Integer; rgbc: array[0..2] of Byte; c: TColor; r, g, b: Byte; begin if (Red = 0) and (Green = 0) and (Blue = 0) then begin Result := False; Exit; end; for i := 0 to Bitmap.Height do begin for j := 0 to Bitmap.Width do begin c := Bitmap.Canvas.Pixels[j, i]; rgbc[0] := GetRValue(c); rgbc[1] := GetGValue(c); rgbc[2] := GetBValue(c); if not (rgbc[0] + Red < 0) and not (rgbc[0] + Red > 255) then rgbc[0] := rgbc[0] + Red; if not (rgbc[1] + Green < 0) and not (rgbc[1] + Green > 255) then rgbc[1] := rgbc[1] + Green; if not (rgbc[2] + Blue < 0) and not (rgbc[2] + Blue > 255) then rgbc[2] := rgbc[2] + Blue; r := rgbc[0]; g := rgbc[1]; b := rgbc[2]; Bitmap.Canvas.Pixels[j, i] := RGB(r, g, b); end; end; Result := True; end;
Ejemplo de Uso:
delphi
procedure TForm1.Button1Click(Sender: TObject); begin SetColorValue(Image1.picture.Bitmap, Spinedit1.Value, Spinedit2.Value, Spinedit3.Value); end;
Saludos!