1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
Unit Unit1;
{$mode objfpc}{$H+}
Interface
Uses
Classes, Sysutils, Fileutil, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, ComCtrls,
LCLType, Math;
Type
{ Tform1 }
Tform1 = Class(Tform)
edtText : Tedit;
Label1 : Tlabel;
Label2 : Tlabel;
pnlView : Tpanel;
tbPosY : Ttrackbar;
tbColorMix : Ttrackbar;
Procedure Formcreate(Sender : Tobject);
Procedure Formshow(Sender : Tobject);
Procedure Tbposychange(Sender : Tobject);
Private
Public
BmpText, BmpFond, BmpOut : TBitmap;
procedure UpdateView;
procedure DoDrawTheText;
End;
type
TRGBTripleArray = array[0..32767] of TRGBTriple;
PRGBTripleArray = ^TRGBTripleArray;
Var
Form1 : Tform1;
Implementation
{$R *.lfm}
{ Tform1 }
Procedure Tform1.Formcreate(Sender : Tobject);
Begin
BmpFond := TBitmap.Create;
BmpFond.SetSize(400,128);
BmpFond.PixelFormat := pf24Bit;
With BmpFond.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := clBlue;
FillRect(0,0,400,128);
End;
BmpText := TBitmap.Create;
BmpText.SetSize(400,128);
BmpText.PixelFormat := pf24Bit;
BmpOut := TBitmap.Create;
BmpOut.SetSize(400,128);
BmpOut.PixelFormat := pf24Bit;
End;
Procedure Tform1.Formshow(Sender : Tobject);
Begin
UpdateView;
End;
Procedure Tform1.Tbposychange(Sender : Tobject);
Begin
UpdateView;
End;
procedure TForm1.DoDrawTheText;
Var
aTextStyle : TTextStyle;
begin
BmpText.BeginUpdate(True);
With BmpText.Canvas do
begin
Clear;
Brush.Style := bsSolid;
Brush.Color := clWhite;
FillRect(0,0,400,128);
Font.Color := clYellow;
With aTextStyle do
begin
Alignment := taCenter;
Layout :=tlTop;
SingleLine := False;
WordBreak := True;
Opaque := True;
RightToLeft := False;
SystemFont := True;
EndEllipsis := True;
End;
Brush.Style := bsClear;
Brush.Color := clNone;
TextRect(Rect(4,0,396,120),4,tbPosY.Position,edtText.Text,aTextStyle);
End;
BmpText.EndUpdate();
end;
Procedure Tform1.Updateview;
const
Seuil = 85; // = 255 div 3
var
CT : pRGBTripleArray; // Couleur pixel Texte
CF, CR : pRGBTripleArray; // Couleur pixel Fond
x, y : integer;
MaxX, MaxY : integer;
function ColorMix(AColor,BColor:TRGBTriple;const Percent : single):TRGBTriple;
var
pct:single;
function ClampByte(const Value: Integer): Byte;
begin
if Value > 255 then
Result := 255
else
if Value < 0 then
Result := 0
else
Result := Value;
end;
begin
pct:=100-Percent;
result.rgbtRed := ClampByte(round( ((AColor.rgbtRed/100) *pct) + ((BColor.rgbtRed/100) *Percent) ));
result.rgbtGreen := ClampByte(round( ((AColor.rgbtGreen/100)*pct) + ((BColor.rgbtGreen/100)*Percent) ));
result.rgbtblue := ClampByte(round( ((AColor.rgbtblue/100) *pct) + ((BColor.rgbtBlue/100) *Percent) ));
end;
Begin
//Boucle maximum sur les plus petites Largeur/Hauteur
MaxX := Min(BmpText.Width, BmpFond.Width);
MaxY := Min(BmpText.Height, BmpFond.Height);
DoDrawTheText;
//BmpOut.SetSize(400,128);
for y := 0 to MaxY-1 do
begin // parcourir les lignes une par une
CT := pRGBTripleArray(BmpText.RawImage.GetLineStart(y));
CF := pRGBTripleArray(BmpFond.RawImage.GetLineStart(y));
CR := pRGBTripleArray(BmpOut.RawImage.GetLineStart(y));
for x := 0 to MaxX-1 do
begin
if (((CT^[x].rgbtRed +CT^[x].rgbtGreen+CT^[x].rgbtBlue) div 3) < Seuil) then
CR^[X] := CF^[X]
else
CR^[x] := ColorMix(CF^[X], CT^[X],tbColorMix.Position);
end;
end;
pnlView.Canvas.Clear;
pnlView.Canvas.Draw(0,0,BmpText); // ------> Avec BmpOut le texte est toujours au milieu !!!!!!!!!
Application.ProcessMessages;
End; |
Partager