close
procedure jbtob(fn:tfilename;image:timage); //判斷JPG OR BMP 丟入image
var abmp:tbitmap;ajpg:tjpegimage;
begin
ABmp := TBitmap.Create;
if AnsiUpperCase(ExtractFileExt(fn))='.BMP' then
ABmp.LoadFromFile(fn)
else begin
AJpg := TJpegImage.Create;
AJpg.LoadFromFile(fn);
ABmp.Assign(AJpg);
AJpg.Free;
end;
image.Picture.Assign(abmp);
abmp.Free;
end;
procedure res(image:timage;panel:tpanel); //長寬調整
var h,w : integer;
begin
image.Width:=Panel.Width;
image.Height:=Panel.Height;
image.AutoSize:=true;
if image.Width>image.Height then //寬>高
begin
h:=round(panel.Width/image.Width*image.Height);
w:=Panel.Width;
if w>panel.Width then //寬>高
begin
h:=round(panel.Width/image.Width*image.Height);
w:=Panel.Width;
end
else if h>panel.Height then //高>寬
begin
w:=round(panel.Height/image.Height*image.Width);
h:=Panel.Height;
end;
end
else if image.Height>image.Width then //高>寬
begin
w:=round(panel.Height/image.Height*image.Width);
h:=Panel.Height;
if w>panel.Width then //寬>高
begin
h:=round(panel.Width/image.Width*image.Height);
w:=Panel.Width;
end
else if h>panel.Height then //高>寬
begin
w:=round(panel.Height/image.Height*image.Width);
h:=Panel.Height;
end;
end;
image.AutoSize:=false;
image.Width:=w;
image.Height:=h;
image.Stretch:=true;
end;
全站熱搜
留言列表