//工程文件
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
//窗体文件
object Form1: TForm1
Left = 3
Top = -1
Width = 792
Height = 584
Caption = '图象的局部放大'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Menu = MainMenu1
OldCreateOrder = False
Position = poDesktopCenter
OnCreate = FormCreate
OnKeyPress = FormKeyPress
OnMouseMove = FormMouseMove
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 784
Height = 538
Align = alClient
TabOrder = 0
object Foreimage: TImage
Left = 128
Top = 0
Width = 329
Height = 449
Stretch = True
OnMouseMove = ForeimageMouseMove
end
object GroupBox1: TGroupBox
Left = 0
Top = 72
Width = 121
Height = 265
Caption = '放大参数设置'
TabOrder = 0
object Label1: TLabel
Left = 19
Top = 24
Width = 66
Height = 13
Caption = '原图局部大小'
end
object Label2: TLabel
Left = 19
Top = 104
Width = 66
Height = 13
Caption = '放大后的大小'
end
object s: TEdit
Left = 16
Top = 60
Width = 89
Height = 21
TabOrder = 0
Text = 's'
end
object d: TEdit
Left = 16
Top = 132
Width = 89
Height = 21
TabOrder = 1
Text = 'd'
end
object Button1: TButton
Left = 16
Top = 208
Width = 75
Height = 25
Caption = '设定'
TabOrder = 2
OnClick = Button1Click
end
end
object Button2: TButton
Left = 8
Top = 16
Width = 75
Height = 33
Caption = '装入图形'
TabOrder = 1
OnClick = Button2Click
end
end
object MainMenu1: TMainMenu
Left = 304
Top = 208
object N1: TMenuItem
Caption = '退出'
OnClick = N1Click
end
end
object OpenDialog1: TOpenDialog
Filter = '*.bmp'
InitialDir = 'c:/'
Left = 88
end
end
//单元文件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Menus;
type
TForm1 = class(TForm)
Panel1: TPanel;
Foreimage: TImage;
GroupBox1: TGroupBox;
s: TEdit;
d: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
MainMenu1: TMainMenu;
N1: TMenuItem;
Button2: TButton;
OpenDialog1: TOpenDialog;
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure ImageCopy(BoxCenterX, BoxCenterY, BoxSide: Integer);
procedure ForeimageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Button1Click(Sender: TObject);
procedure N1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
sSide:Integer=60;dSide:Integer=100; //原图大小和放大后的大小
bmp:TBitmap;
var
msHide: Boolean;
OldX, OldY, NewX, NewY: Integer;
DestRect, SourceRect : TRect;
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
s.text:=inttostr(sSide);
d.text:=inttostr(dSide);
bmp:=Tbitmap.Create;
//bmp.LoadFromFile('');
//ForeImage.Picture.LoadFromFile('');
Canvas.CopyMode:=cmSrcCopy;
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if not msHide then
begin
msHide:=True;
ShowCursor(True);
ImageCopy(OldX, OldY, dSide);
end;
end;
procedure TForm1.ImageCopy(BoxCenterX, BoxCenterY, BoxSide: Integer);
begin
//bmptemp:=TBitmap.Create;
with SourceRect do
begin
Left:=BoxCenterX-BoxSide;
Top:=BoxCenterY-BoxSide;
Right:=BoxCenterX+BoxSide;
Bottom:=BoxCenterY+BoxSide;
end;
//bmptemp.Canvas.CopyRect(re,bmp.canvas,SourceRect);
with DestRect do
begin
Left:=BoxCenterX-dSide;
Top:=BoxCenterY-dSide;
Right:=BoxCenterX+dSide;
Bottom:=BoxCenterY+dSide;
end;
ForeImage.Canvas.CopyRect(DestRect, bmp.Canvas, SourceRect);
//ForeImage.Canvas.StretchDraw(DestRect,bmp);
end;
procedure TForm1.ForeimageMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
NewX:=X;
NewY:=Y;
if msHide then
begin
OldX:=NewX;
OldY:=NewY;
msHide:=False;
ShowCursor(False);
end else
begin
ImageCopy(OldX, OldY, dSide);
end;
ImageCopy(NewX, NewY, sSide);
OldX:=NewX;
OldY:=NewY;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
sSide:=strtoint(s.text);
dSide:=strtoint(d.text);
end;
procedure TForm1.N1Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
w,h,w1,h1:Integer;
rec:Trect;
begin
if OpenDialog1.Execute then
begin
bmp.LoadFromFile(Opendialog1.FileName);
foreimage.AutoSize:=true;
foreimage.Picture.LoadFromFile(Opendialog1.FileName);
foreimage.AutoSize:=false;
end;
end;
end.