, har du nogensinde haft lyst til at male et bitmap flisebelagt?- i midten?strakt ud?denne klasse, her er en klasse, jeg fandt for længe siden, fra en af de mistede hukommelsen kilder, og dens eneste formål er at male på baggrund af et vindue ved hjælp af et bestemt billede (du kan udvide dens anvendelse ved hjælp af tgraphic efterkommere, som f.eks. tjpegpicture, tilføje jpeg - i bruger klausul; tgifimage, tilføje anders melanders gif; osv.), enhed bgpaint;,,, grænseflade,, anvender, vinduer, grafik, klasser,,,,,,,,, ttilebackstyle = (tbsnone, tbspiccenter, tbspicclip, tbspicfit, tbspicheigth,,, tbspicstretch, tbspictile, tbspicwidth);,,, ttileback = klasse (tpersistent), private, fpicture: tpicture;,, fstyle: ttilebackstyle;,, fonchange: tnotifyevent;,,, procedure setstyle (denne værdi: ttilebackstyle);,, procedure setonchange (const - værdi: tnotifyevent);,, procedure setpicture (denne værdi: tpicture), offentlig, konstruktøren skabe;,, destructor ødelægge; gearvalg;,, procedure tildele (kilde: tpersistent); gearvalg;,,, funktion, tom: boolean,,, procedure trække (denne lærred: tcanvas; denne arect - trect);,, ejendom onchange: tnotifyevent læse fonchange skrive setonchange;,, der er offentliggjort, ejendom, billede: tpicture læse fpicture skrive setpicture;,, ejendom, stil: ttilebackstyle læse fstyle skrive setstyle misligholdelse tbsnone,,,,,,,,, ttileback} {gennemførelse,,,,,,, ttileback tildele (procedure. kilde: tpersistent), begynder, hvis kilde er ttileback, med ttileback (kilde), begynder, self.fstyle: = stil,,, Self.Picture:= Picture;,, end,, else,, inherited,, end;,,, constructor TTileBack.Create;,, begin,, FPicture := TPicture.Create;,, FStyle := tbsNone;,, end;,,, destructor TTileBack.Destroy;,, begin,, FPicture.Free;,, inherited Destroy;,, end;,,, procedure TTileBack.Draw(const Canvas: TCanvas; const ARect: TRect);,, var,, Dest: TRect;,, XPos, YPos, RWidth, RHeight: Integer;,, PicRatio, ImageRatio: Double;,, begin,, if Empty then Exit;,,, RWidth := ARect.Right - ARect.Left;,, RHeight:= ARect.Bottom- ARect.Top;,, XPos := 0;,, YPos := 0;,,, case Style of,, tbsNone: Exit;,,, tbsPicClip:,, Canvas.Draw(ARect.Left, ARect.Top, Picture.Graphic);,,, tbsPicCenter:,, begin,, XPos := ARect.Left + (RWidth - Picture.Width) div 2;,, YPos := ARect.Top + (RHeight- Picture.Height)div 2;,, Canvas.Draw(XPos, YPos, Picture.Graphic);,, end;,,, tbsPicFit:,, begin,, if (FPicture.Width > 0) and (FPicture.Height > 0) then,, begin,, PicRatio := Picture.Height /Picture.Width;,, ImageRatio:=RHeight /RWidth;,, if PicRatio > ImageRatio then,, begin,, XPos := Trunc(RHeight /PicRatio);,, YPos := RHeight;,, end,, else,, begin,, XPos := RWidth;,, YPos := Trunc( RWidth * PicRatio );,, end;,, end;,, Dest := Rect( 0,0,XPos, YPos);,, OffsetRect(Dest, ARect.Left, ARect.Top);,, lærred. stretchdraw (dest, billede. grafisk);,,,,,, tbspicheigth:,, begynder, xpos: = trunc (fpicture.width * (rheight /billede. højde),,, ypos: = rheight;,, dest: = direkte (0, 0, xpos, ypos),,, offsetrect (dest, arect. venstre, arect. top), lærred. stretchdraw (dest, fpicture. grafisk);,,,,,, tbspicstretch:,, lærred. stretchdraw (arect billede. grafisk);,,, tbspictile:,, begynder, xpos: = arect. venstre, mens xpos < arect. ret, begynder, ypos: = arect. top;,, mens ypos < arect. bunden, begynder, lærred. træk (xpos, ypos billede. grafisk);,, ypos: = ypos + fpicture. højde,,,end;,, XPos := XPos + Picture.Width;,, end;,, end;,,, tbsPicWidth:,, begin,, XPos := RWidth;,, YPos := Trunc(RWidth * (Picture.Height /Picture.Width));,, Dest := Rect(0,0, XPos, YPos);,, OffsetRect(Dest, ARect.Left, ARect.Top);,, Canvas.StretchDraw(Dest, Picture.Graphic);,, end;,, end;,, end;,,, function TTileBack.Empty: Boolean;,, begin,, Result := (Style = tbsNone) or,, ((Style in [tbsPicClip, tbsPicFit, tbsPicHeigth, tbsPicStretch, tbsPicTile, tbsPicWidth]) and,, ((Picture = nil) or (Picture.Graphic = nil) or (Picture.Graphic.Empty))),, end;,,, procedure TTileBack.SetOnChange(const Value: TNotifyEvent);,, begin,, FOnChange := Value;,, FPicture.OnChange := Value;,, end;,,, procedure TTileBack.SetPicture(const Value: TPicture);,, begin,, FPicture.Assign( Value );,, end;,,, procedure TTileBack.SetStyle(const Value: TTileBackStyle);,, begin,, if FStyle <> Value then,, begin,, FStyle := Value;,, if Assigned(FOnChange) then,, FOnChange(Self);,, end;,, end;,,, end.,,, Here is a quick and dirty example of its usage and powers:,,,, unit bgpaintex1;,,, interface,,, uses,, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,,, ExtCtrls, bgPaint, StdCtrls, JPeg;,,, type,, TForm1 = class(TForm),, Image1: TImage;,, ComboBox1: TComboBox;,, Button1: TButton;,, OpenDialog1: TOpenDialog;,, procedure FormCreate(Sender: TObject);,, procedure FormPaint(Sender: TObject);,, procedure ComboBox1Change(Sender: TObject);,, procedure Button1Click(Sender: TObject);,, private,, { Private declarations },, public,, { Public declarations },, aBG: TTileBack;,, end;,,, var,, Form1: TForm1;,,, implementation,,, uses TypInfo;,,, {$R *.DFM},,, procedure TForm1.FormCreate(Sender: TObject);,, var i: TTileBackStyle;,, begin,, aBG := TTileBack.Create;,, aBG.Picture := Image1.Picture;,, aBG.Style := tbsPicFit;,, for i := tbsNone to tbsPicWidth do,, begin,, ComboBox1.Items.AddObject(GetEnumName(TypeInfo(TTileBackStyle), Integer(i)), TObject(i));,, end;,, end;,,, procedure TForm1.FormPaint(Sender: TObject);,, begin,, aBG.Draw(Canvas, ClientRect);,, end.,,, procedure tform1. combobox1change (afsender: tobject), begynder, abg. stil: = ttilebackstyle (combobox1. poster. genstande [combobox1. itemindex]), ugyldig;,,,,,, procedure tform1. button1click (afsender: tobject), begynder, hvis opendialog1. udfør så, begynder, image1. billede. loadfromfile (opendialog1. filnavn);,, abg. foto: = image1. billede, for ugyldig,,,,,,,,,,.,,
baggrund maler klasse
Previous:en nyere sager menu
Next Page:web services - enkelt i delphi - 6...