Untuk membuat efek mirror Anda dapat menggunakan fungsi StretchBlt. Fungsi StretchBlt digunakan untuk menyalin bitmap dari satu rectangle asal ke rectangle tujuan.
unit UMain; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls; type TForm5 = class(TForm) Image1: TImage; Image2: TImage; BitBtn1: TBitBtn; BitBtn2: TBitBtn; procedure BitBtn1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); private { Private declarations } procedure VerticalMirror(Asal, Tujuan: TBitmap); procedure HorizontalMirror(Asal, Tujuan: TBitmap); public { Public declarations } end; var Form5: TForm5; implementation {$R *.dfm} procedure TForm5.VerticalMirror(Asal, Tujuan: TBitmap); begin Tujuan.Assign(nil); Tujuan.Width:= Asal.Width; Tujuan.Height:= Asal.Height; StretchBlt(Tujuan.Canvas.Handle, 0, 0, Tujuan.Width, Tujuan.Height, Asal.Canvas.Handle, 0, Asal.Height, Asal.Width, -Asal.Height, SRCCOPY); end; procedure TForm5.BitBtn1Click(Sender: TObject); var Temp: TBitmap; begin Temp:= TBitmap.Create; Temp.Assign(Image1.Picture.Bitmap); HorizontalMirror(Temp, Image2.Picture.Bitmap); Temp.Free; end; procedure TForm5.BitBtn2Click(Sender: TObject); var Temp: TBitmap; begin Temp:= TBitmap.Create; Temp.Assign(Image1.Picture.Bitmap); VerticalMirror(Temp, Image2.Picture.Bitmap); Temp.Free; end; procedure TForm5.HorizontalMirror(Asal, Tujuan: TBitmap); begin Tujuan.Assign(nil); Tujuan.Width:= Asal.Width; Tujuan.Height:= Asal.Height; StretchBlt(Tujuan.Canvas.Handle, 0, 0, Tujuan.Width, Tujuan.Height, Asal.Canvas.Handle, Asal.Width, 0, -Asal.Width, Asal.Height, SRCCOPY); end; end.
Comments
Post a Comment