使
procedure CutImg(src,dest:string;width,height:Integer);
var
ImgEV:TImageEnView;
Bigratio,ratio:Extended;
ReTop,ReLeft,ReWidth,ReHeight:Integer;
Blur:Extended;
begin
ImgEV:=TImageEnView.Create(nil);
ImgEV.IO.Bitmap.Canvas.Pen.Color := clWhite;
ImgEV.IO.Bitmap.Canvas.Pen.Style := psSolid;
ImgEV.IO.Bitmap.Canvas.Brush.Color := clWhite;
ImgEV.IO.Bitmap.Canvas.Brush.Style := bsSolid;
ImgEV.IO.LoadFromFileJpeg(src);
ReWidth:=width;
ReHeight:=height;
if width>ImgEV.Bitmap.Width then
ReWidth := ImgEV.Bitmap.Width;
if height>ImgEV.Bitmap.height then
ReHeight := ImgEV.Bitmap.height;
Bigratio:=ImgEV.Bitmap.Width/ImgEV.Bitmap.Height;
ratio:=ReWidth/ReHeight;
if ratio > Bigratio then
begin
ReWidth:=Round(ReHeight*Bigratio);
end else if ratio < Bigratio then begin
ReHeight:=Round(ReWidth/Bigratio);
end;
if (width>ImgEV.Bitmap.Width) and (height>ImgEV.Bitmap.height) then
Blur:=0
else
Blur:=(ImgEV.Bitmap.Width/ReWidth)/4+0.2;
ImgEV.Proc.Blur(Blur);
ReTop:=Round((height-ReHeight)/2);
ReLeft:=Round((width-ReWidth)/2);
ImgEV.IO.Bitmap.Canvas.StretchDraw(Rect(0, 0, ReWidth, ReHeight),ImgEV.Bitmap);
ImgEV.Bitmap.Width :=width;
ImgEV.Bitmap.Height :=height;
if (ReLeft>0) or (ReTop>0) then
begin
ImgEV.IO.Bitmap.Canvas.Draw(ReLeft,ReTop,ImgEV.Bitmap);
ImgEV.IO.Bitmap.Canvas.Rectangle(0,0,width,ReTop);
ImgEV.IO.Bitmap.Canvas.Rectangle(ReWidth+ReLeft,0,width,height);
ImgEV.IO.Bitmap.Canvas.Rectangle(0,ReHeight+ReTop,width,height);
ImgEV.IO.Bitmap.Canvas.Rectangle(0,0,ReLeft,height);
end;
ImgEV.IO.SaveToFileJpeg(dest);
ImgEV.Free;
end;