{Power by hzqghost@21cn.com}
unit CutWater;
interface
uses
Math,imageenview,
SysUtils, Classes, Graphics;
procedure CutImg(src,dest:string;width,height:Integer);//截图
procedure Water(src,png:string);//水印
implementation
procedure CutImg(src,dest:string;width,height:Integer);
var
ImageEnView1:TImageEnView;
Bigratio,ratio:Extended;
ReTop,ReLeft,ReWidth,ReHeight:Integer;
Blur:Extended;
begin
ImageEnView1:=TImageEnView.Create(nil);
ImageEnView1.IO.Bitmap.Canvas.Pen.Color := clWhite;
ImageEnView1.IO.Bitmap.Canvas.Pen.Style := psSolid;
ImageEnView1.IO.Bitmap.Canvas.Brush.Color := clWhite;
ImageEnView1.IO.Bitmap.Canvas.Brush.Style := bsSolid;
ImageEnView1.IO.LoadFromFileJpeg(src);
ReWidth:=width;
ReHeight:=height;
if width>ImageEnView1.Bitmap.Width then
ReWidth := ImageEnView1.Bitmap.Width;
if height>ImageEnView1.Bitmap.height then
ReHeight := ImageEnView1.Bitmap.height;
Bigratio:=ImageEnView1.Bitmap.Width/ImageEnView1.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>ImageEnView1.Bitmap.Width) and (height>ImageEnView1.Bitmap.height) then
Blur:=0
else
Blur:=(ImageEnView1.Bitmap.Width/ReWidth)/4+0.2;
ImageEnView1.Proc.Blur(Blur);
ReTop:=Round((height-ReHeight)/2);
ReLeft:=Round((width-ReWidth)/2);
ImageEnView1.IO.Bitmap.Canvas.StretchDraw(Rect(0, 0, ReWidth, ReHeight),ImageEnView1.Bitmap);
ImageEnView1.Bitmap.Width :=width;
ImageEnView1.Bitmap.Height :=height;
if (ReLeft>0) or (ReTop>0) then
begin
ImageEnView1.IO.Bitmap.Canvas.Draw(ReLeft,ReTop,ImageEnView1.Bitmap);
ImageEnView1.IO.Bitmap.Canvas.Rectangle(0,0,width,ReTop);
ImageEnView1.IO.Bitmap.Canvas.Rectangle(ReWidth+ReLeft,0,width,height);
ImageEnView1.IO.Bitmap.Canvas.Rectangle(0,ReHeight+ReTop,width,height);
ImageEnView1.IO.Bitmap.Canvas.Rectangle(0,0,ReLeft,height);
end;
ImageEnView1.IO.SaveToFileJpeg(dest);
ImageEnView1.Free;
end;
procedure Water(src,png:string);
var
X,Y:Integer;
ImageEnView1:TImageEnView;
jpgWidth,jpgHeight:Integer;
pngWidth,pngHeight:Integer;
begin
ImageEnView1:=TImageEnView.Create(nil);
ImageEnView1.IO.LoadFromFilePNG(png);
pngWidth:=ImageEnView1.Bitmap.Width;
pngHeight:=ImageEnView1.Bitmap.Height;
ImageEnView1.LayersAdd;
ImageEnView1.IO.LoadFromFileJpeg(src);
jpgWidth:=ImageEnView1.Bitmap.Width;
jpgHeight:=ImageEnView1.Bitmap.Height;
X := Round((ImageEnView1.Bitmap.Width-pngWidth) / 2);
Y := Round((ImageEnView1.Bitmap.Height-pngHeight) / 2);
ImageEnView1.Layers[0].PosX := X;
ImageEnView1.Layers[0].PosY := Y;
ImageEnView1.LayersMerge(1, 0);
ImageEnView1.Bitmap.Width:=jpgWidth;
ImageEnView1.Bitmap.Height:=jpgHeight;
ImageEnView1.IO.SaveToFileJpeg(src);
ImageEnView1.Free;
end;
end.
转载于:https://my.oschina.net/u/582827/blog/492116