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
| procedure TForm1.aTraiterWH(srcBitMap, dstBitMap : TBitmap; aHeight,
aWidth : Integer; TraitG, TraitD, TraitH, TraitB : integer);
{Les TraitX sont comptés à partir des coins}
var
{srcBitMap}
cRect : TRect; //Strechés W et H
ghRect, dhRect, dbrect, gbRect : TRect; //Non strechés
mhRect, mbRect : Trect; //Strechés W
gmRect, dmRect : Trect; //Strechés H
{dstBitMap} //dRect : Rect de destination
dRect : TRect;
dTraitG, dTraitD, dTraitH, dTraitB : Integer; //Position des traits
{Variables Tmp}
srcCanvas : TCanvas;
BitMapTmp : TBitmap;
begin
try
BitMapTmp := TBitmap.Create;
{L'image d'origine}
srcCanvas := srcBitMap.Canvas;
{Les coins}
ghRect := Rect(0, 0, TraitG, TraitH);
srcCanvas.CopyRect(ghRect, srcCanvas, ghRect);
dhRect := Rect(srcCanvas.Width -TraitD, 0, srcCanvas.Width, TraitH);
srcCanvas.CopyRect(dhRect, srcCanvas, dhRect);
dbRect := Rect(srcCanvas.Width -TraitD,srcCanvas.Height-TraitB, srcCanvas.Width, srcCanvas.Height);
srcCanvas.CopyRect(dbRect, srcCanvas, dbRect);
gbRect := Rect(0, srcCanvas.Height-TraitB, TraitG, srcCanvas.Height);
srcCanvas.CopyRect(gbRect, srcCanvas, gbRect);
{Les bords}
mhRect := Rect(TraitG, 0, srcCanvas.Width -TraitD, TraitH);
srcCanvas.CopyRect(mhRect, srcCanvas, mHRect);
dmRect := Rect(srcCanvas.Width -TraitD, TraitH, srcCanvas.Width, srcCanvas.Height-TraitB);
srcCanvas.CopyRect(mhRect, srcCanvas, mHRect);
mbRect := Rect(TraitG, srcCanvas.Height-TraitB, srcCanvas.Width -TraitD, srcCanvas.Height);
srcCanvas.CopyRect(mhRect, srcCanvas, mHRect);
gmRect := Rect(0, TraitH, TraitG, srcCanvas.Height-TraitB);
srcCanvas.CopyRect(gmRect, srcCanvas, gmRect);
{Le centre}
cRect := Rect(TraitG, TraitH, srcCanvas.Width -TraitD, srcCanvas.Height-TraitB);
srcCanvas.CopyRect(cRect, srcCanvas, cRect);
{-}
{Caractéristiques de l'image temporaire de destination}
BitMapTmp.Width := aWidth;
BitMapTmp.Height := aHeight;
dTraitG := TraitG;
dTraitH := TraitH;
dTraitD := aWidth - TraitD;
dTraitB := aHeight - TraitB;
{Construction de l'image temporaire}
with BitMapTmp.Canvas do begin
dRect := Rect(0, 0, dTraitG, dTraitH);
CopyRect(dRect, srcCanvas, ghRect);
dRect := Rect(dTraitG, 0, DTraitd, dTraitH);
CopyRect(dRect, srcCanvas, mhRect);
dRect := Rect(dTraitD, 0, aWidth, dTraitH);
CopyRect(dRect, srcCanvas, dhRect);
dRect := Rect(dTraitD, dTraitH, aWidth, dTraitB);
CopyRect(dRect, srcCanvas, dmRect);
dRect := Rect(dTraitD, dTraitB, aWidth, aHeight);
CopyRect(dRect, srcCanvas, dbRect);
dRect := Rect(dTraitG, dTraitB, dTraitD, aHeight);
CopyRect(dRect, srcCanvas, mbRect);
dRect := Rect(0, dTraitB, dTraitG, aHeight);
CopyRect(dRect, srcCanvas, gbRect);
dRect := Rect(0, dTraitH, dTraitG, dTraitB);
CopyRect(dRect, srcCanvas, gmRect);
dRect := Rect(dTraitG, dTraitH, dTraitD, dTraitB);
CopyRect(dRect, srcCanvas, cRect);
end;
dstBitMap.assign(BitMapTmp);
finally
BitMapTmp.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
aTraiterWH(Image1.Picture.Bitmap, Image2.Picture.Bitmap, Image2.Height, Image2.Width, 4, 4, 4, 4);
end; |
Partager