//缩----------------------------------------------
procedure TForm1.sp_sClick(Sender: TObject);
begin
if not((image1.width<18)or(image1.Height<18)) then
begin
Where_the_Form;
//合适----------------------------------------------
procedure TForm1.sp_fitClick(Sender: TObject);
begin
show_picture_fit_size;
where_show_picture;
end;
-------------------------------自定义过程-----------
----------------------------------------------------
//将商取整,返回值为integer 型
function TForm1.int_from_div(aNum:real):integer;
var aa1:string;
begin
aa1 :=floattostr(int(aNum)); //div 是整数除,
result :=strtoint(aa1); //mod 是整数余
end;
//将加载图片的尺寸赋给 image1
procedure TForm1.load_picture_size;
begin
image1.Height :=image1.Picture.Height;
image1.Width :=image1.Picture.Width;
end;
//显示图片的位置(左上点坐标)
//.. 要调用int_from_div()
procedure TForm1.where_show_picture;
begin
if image1.width<Panel2.Width then
image1.Left :=int_from_div((panel2.Width-image1.Width)div 2)
else
image1.Left :=4;
if image1.Height<panel2.Height then
image1.Top :=int_from_div(int((panel2.Height-image1.Height)div 2))
else
image1.Top :=4;
end;
//以合适的尺寸显示整个图片
procedure TForm1.show_picture_fit_size;
var
aa01,aa02:integer;
pp01,pp02:integer;
begin
aa01 := image1.Picture.Height;
aa02 := image1.Picture.Width;
pp01 := screen.Height - 100; //去除窗口边框的高度
pp02 := screen.Width - 16; //去除窗口边框的宽度
if aa01 * pp02 / aa02 / pp01 - 1 > 0 then
if aa01 > pp01 then //图片高度较大
begin
image1.Height := pp01;
image1.Width := int_from_div(aa02 * pp01 div aa01);
rule_1 := pp01;
rule_2 := aa01;
end else begin
load_picture_size;
end;
if aa01 * pp02 / aa02 / pp01 - 1 < 0 then
if aa02 >pp02 then
begin
image1.Width := pp02;
image1.Height := int_from_div(aa01 * pp02 div aa02);
form1.Left := 0;
form1.Top := 0;
form1.Height := image1.Height + 100;
form1.Width := image1.Width + 16;
rule_1 := pp02;
rule_2 := aa02;
end else begin
load_picture_size;
end;
if aa01 / aa02 = pp01 / pp02 then
begin
if aa01 > pp01 then
begin
image1.Height := pp01;
image1.Width := pp02;
form1.Left := 0;
form1.Top := 0;
form1.Height := screen.Height;//image1.Height + 100;
form1.Width := screen.Width;//image1.Width + 16;
rule_1 := pp01;
rule_2 := aa01;
end else begin
load_picture_size;
form1.Height := image1.Height + 100;
form1.Width := image1.Width + 16;
rule_1 := 1;
rule_2 := 1;
end;
end;
end;
//窗口适应图片的大小 (窗口 < 图片时) 图片在窗口上的位置
procedure TForm1.show_picture_window_size;
begin
if not(image1.width+ 8< panel2.Width) then
Form1.Width :=image1.Width +16; //image 到 form 边框宽-象素
if not(image1.Height+ 8< panel2.Height) then
Form1.Height :=image1.Height +100; //image 到 form 边框高-象素
end;
//窗口适应图片的大小 (窗口 >> 图片时) 图片在窗口上的位置
procedure TForm1.show_picture_window_size_II;
begin
if (form1.width>449)and(form1.Height>276) then
begin
form1.Width :=image1.Width+16; //image 到 form 边框宽-象素
form1.Height :=image1.Height+100; //image 到 form 边框高-象素
end;
if (form1.width>449)and(not(form1.Height>276)) then
form1.Width :=image1.Width+16;
if (not(form1.width>449))and(form1.Height>276) then
form1.Height :=image1.Height+100;
end;
//窗口在屏幕上的位置
procedure TForm1.Where_the_Form;
begin
end;
//缩小显示的图象
procedure TForm1.suoxiao;
begin
image1.Width := int_from_div((image1.Width div 3)*2);
image1.Height := int_from_div((image1.Height div 3)*2);