用 ImageEnView 给图片加水印/建缩略图

使

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;

 


procedure Water(src,png:string);
var
   X,Y:Integer;
   ImgEV:TImageEnView;
   jpgWidth,jpgHeight:Integer;
   pngWidth,pngHeight:Integer;
begin
   ImgEV:
=TImageEnView.Create(nil);
   ImgEV.IO.LoadFromFilePNG(png);
   pngWidth:
=ImgEV.Bitmap.Width;
   pngHeight:
=ImgEV.Bitmap.Height;
   ImgEV.LayersAdd;
   ImgEV.IO.LoadFromFileJpeg(src);
   jpgWidth:
=ImgEV.Bitmap.Width;
   jpgHeight:
=ImgEV.Bitmap.Height;
   X :
= Round((ImgEV.Bitmap.Width-pngWidth) / 2);
   Y :
= Round((ImgEV.Bitmap.Height-pngHeight) / 2);
   ImgEV.Layers[
0].PosX := X;
   ImgEV.Layers[
0].PosY := Y;
   ImgEV.LayersMerge(
1, 0);
   ImgEV.Bitmap.Width:
=jpgWidth;
   ImgEV.Bitmap.Height:
=jpgHeight;
   ImgEV.IO.SaveToFileJpeg(src);
   ImgEV.Free;
end;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值