unit NewImagePanel;
interface
uses
Windows,SysUtils, Classes, Controls, ExtCtrls,Graphics,Dialogs,Forms;
type
RMRect=record
A:TRect;
B:TRect;
C:TRect;
D:TRect;
AB:TRect;
AC:TRect;
BD:TRect;
CD:TRect;
WA:TRect;
WB:TRect;
WC:TRect;
WD:TRect;
WAB:TRect;
WAC:TRect;
WBD:TRect;
WCD:TRect;
X,Y,W,H:Integer;
WX,WY,WW,WH:Integer;
end;
TWatermarkImage = class(TImage)
private
{ Private declarations }
IsClikW,MUp:Boolean;
WMPoint:TPoint;
XRect:TRect;
protected
{ Protected declarations }
procedure WFrameMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure WFrameMouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
procedure WFrameMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
public
{ Public declarations }
published
{ Published declarations }
constructor Create(Aowner:TComponent);override;
destructor Destroy;override;
end;
TNewFrameimage = class(TImage)
private
FrameBrokenRect:TRect;
MLeftDown,MUp:Boolean;
MPoint:TPoint;
{ Private declarations }
protected
{ Protected declarations }
procedure FrameMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure FrameMouseDown(Sender: TObject; Button: TMouseButton;Shift: TShiftState; X, Y: Integer);
procedure FrameMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
public
{ Public declarations }
published
{ Published declarations }
constructor Create(Aowner:TComponent);override;
destructor Destroy;override;
end;
TNewimage = class(TImage)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
constructor Create(Aowner:TComponent);override;
destructor Destroy;override;
end;
TNewimagePanel = class(TWinControl)
private
{ Private declarations }
Newimage:TNewimage;
NewFrameimage:TNewFrameimage;
WatermarkImage:TWatermarkImage;
FFrameRect: TRect;
PicImageRect:TRect;
Cbmp:TBitmap;
FPicture:TPicture;
FWatermarkPic: TPicture;
WatkBit:TBitmap;
procedure CanvasRec(CR: TRect; CCanvas: Tcanvas;Kind:Boolean=true);
procedure SetPicture(const Value:TPicture);
procedure SetFrameRect(const Value:TRect);
procedure SetWatermarkPic(const Value:TPicture);
procedure PaintPic(ACanvas: TCanvas; Bitmap: TBitmap);
function StretchDraw(BigBmp: TBitmap; Width, Height,
Edge: Integer): TBitmap;
protected
{ Protected declarations }
public
{ Public declarations }
property FrameRect:TRect read FFrameRect write SetFrameRect;
procedure Refresh;
procedure ShowWatermark;
procedure FullScreen;
published
{ Published declarations }
constructor Create(Aowner:TComponent);override;
destructor Destroy;override;
property Picture: TPicture read FPicture write SetPicture;
property WatermarkPic:TPicture read FWatermarkPic write SetWatermarkPic;
end;
var
Cmr:RMRect;
const
FOCUS_FRAME=20;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TNewimagePanel]);
end;
{ TNewimage }
constructor TNewimage.Create(Aowner: TComponent);
begin
inherited;
end;
destructor TNewimage.Destroy;
begin
inherited;
;
end;
constructor TNewFrameimage.Create(Aowner: TComponent);
begin
inherited;
end;
destructor TNewFrameimage.Destroy;
begin
inherited;
end;
procedure TNewFrameimage.FrameMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
XRect:TRect;
begin
with TNewimagePanel(Owner) do
XRect:=Rect(PicImageRect.Left-4,PicImageRect.Top-4,PicImageRect.Right+4,PicImageRect.Bottom+4);
TNewimagePanel(Owner).WatermarkImage.IsClikW:=false;
TNewimagePanel(Owner).ShowWatermark;
if PtInRect(XRect,Point(x,Y)) then
begin
MLeftDown:=true;
MPoint:=Point(x,y);
if (PtInRect(Cmr.A,Point(x,Y))) or (PtInRect(Cmr.AB,Point(x,Y))) or (PtInRect(Cmr.B,Point(x,Y)))
or (PtInRect(Cmr.AC,Point(x,Y))) then
MUp:=true
else
MUp:=false
end;
end;
procedure TNewFrameimage.FrameMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
Spoint:TPoint;
cx,cy:integer;
Sleft,STop,SWidth,SHeight:integer;
XRect:TRect;
CursorRect:TRect;
begin
with TNewimagePanel(Owner) do
XRect:=Rect(PicImageRect.Left-4,PicImageRect.Top-4,PicImageRect.Right+4,PicImageRect.Bottom+4);
if (MLeftDown) and PtInRect(XRect,Point(x,Y)) then
begin
if Owner.ClassName = 'TNewimagePanel' then
begin
Sleft:=TNewimagePanel(Owner).PicImageRect.Left;
STop:=TNewimagePanel(Owner).PicImageRect.Top;
SWidth:=TNewimagePanel(Owner).PicImageRect.Right;
SHeight:=TNewimagePanel(Owner).PicImageRect.Bottom;
end;
if Cursor=crSizeAll then
FrameBrokenRect := Rect(x-MPoint.x+Cmr.X,Y-(MPoint.Y-Cmr.Y),x-MPoint.x+Cmr.X+(Cmr.w-Cmr.x),Y-(MPoint.Y-Cmr.Y)+(Cmr.h-Cmr.y));
if Cursor=crSizeNWSE then
if MUp then
FrameBrokenRect := Rect(x-MPoint.x+Cmr.X,Y-(MPoint.Y-Cmr.Y),Cmr.w,Cmr.h)
else
FrameBrokenRect := Rect(Cmr.X,Cmr.Y,x-MPoint.x+Cmr.X+(Cmr.w-Cmr.x),Y-(MPoint.Y-Cmr.Y)+(Cmr.h-Cmr.y)) ;
if Cursor=crSizeNESW then
if MUp then
FrameBrokenRect := Rect(Cmr.X,Y-(MPoint.Y-Cmr.Y),x-MPoint.x+Cmr.X+(Cmr.w-Cmr.x),Cmr.h)
else
FrameBrokenRect := Rect(x-MPoint.x+Cmr.X,Cmr.Y,Cmr.w,Y-(MPoint.Y-Cmr.Y)+(Cmr.h-Cmr.y)) ;
if Cursor=crSizeNS then
if MUp then
FrameBrokenRect := Rect(Cmr.X,Y-(MPoint.Y-Cmr.Y),Cmr.w,Cmr.h)
else
FrameBrokenRect := Rect(Cmr.X,Cmr.Y,Cmr.w,Y-(MPoint.Y-Cmr.Y)+(Cmr.h-Cmr.y)) ;
if self.Cursor=crSizeWE then
if MUp then
FrameBrokenRect := Rect(x-MPoint.x+Cmr.X,Cmr.Y,Cmr.W,Cmr.h)
else
FrameBrokenRect := Rect(Cmr.X,Cmr.Y,x-MPoint.x+Cmr.X+(Cmr.w-Cmr.x),Cmr.h);
if FrameBrokenRect.Left<SLeft then FrameBrokenRect.Left:=SLeft-1;
if FrameBrokenRect.Top<STop then FrameBrokenRect.Top:=STop-1;
if FrameBrokenRect.Right>SWidth then FrameBrokenRect.Right:=SWidth+1;
if FrameBrokenRect.Bottom>SHeight then FrameBrokenRect.Bottom:=SHeight+1;
if Cursor<>crSizeAll then
begin
if FrameBrokenRect.Right-FrameBrokenRect.Left<FOCUS_FRAME then
if FrameBrokenRect.Left+1=Sleft then
FrameBrokenRect.Right:=FrameBrokenRect.Left+FOCUS_FRAME
else
if Mup then
if Cursor=crSizeNESW then
FrameBrokenRect.Right:=FrameBrokenRect.Left+FOCUS_FRAME
else
FrameBrokenRect.Left:=FrameBrokenRect.Right-FOCUS_FRAME
else
if Cursor=crSizeNESW then
FrameBrokenRect.Left:=FrameBrokenRect.Right-FOCUS_FRAME
else
FrameBrokenRect.Right:=FrameBrokenRect.Left+FOCUS_FRAME;
if FrameBrokenRect.Bottom-FrameBrokenRect.Top<FOCUS_FRAME then
if FrameBrokenRect.Top+1=STop then
FrameBrokenRect.Bottom:=FrameBrokenRect.Top+FOCUS_FRAME
else
if Mup then
FrameBrokenRect.Top:=FrameBrokenRect.Bottom-FOCUS_FRAME
else
FrameBrokenRect.Bottom:=FrameBrokenRect.Top+FOCUS_FRAME;
//限制缩小范围
if FrameBrokenRect.Left>TNewimagePanel(Owner).WatermarkImage.Left then
FrameBrokenRect.Left:=TNewimagePanel(Owner).WatermarkImage.Left;
if FrameBrokenRect.Top>TNewimagePanel(Owner).WatermarkImage.Top then
FrameBrokenRect.Top:=TNewimagePanel(Owner).WatermarkImage.Top;
if FrameBrokenRect.Right<TNewimagePanel(Owner).WatermarkImage.Left+TNewimagePanel(Owner).WatermarkImage.Width then
FrameBrokenRect.Right:=TNewimagePanel(Owner).WatermarkImage.Left+TNewimagePanel(Owner).WatermarkImage.Width ;
if FrameBrokenRect.Bottom<TNewimagePanel(Owner).WatermarkImage.Top+TNewimagePanel(Owner).WatermarkImage.Height then
FrameBrokenRect.Bottom:=TNewimagePanel(Owner).WatermarkImage.Top+TNewimagePanel(Owner).WatermarkImage.Height;
end
else
begin
if FrameBrokenRect.Bottom-FrameBrokenRect.Top<Cmr.H-Cmr.Y then
if FrameBrokenRect.Top=STop-1 then
FrameBrokenRect.Bottom:=Cmr.H-Cmr.Y+STop-1
else
FrameBrokenRect.Top:=FrameBrokenRect.Bottom-Cmr.H+Cmr.Y;
if FrameBrokenRect.Right-FrameBrokenRect.Left<Cmr.W-Cmr.X then
if FrameBrokenRect.Left=SLeft-1 then
FrameBrokenRect.Right:=SLeft+Cmr.W-Cmr.X-1
else
FrameBrokenRect.Left:=FrameBrokenRect.Right-Cmr.W+Cmr.X;
end;
canvas.FillRect(Rect(0, 0, Width, Height));
DrawFocusRect(Canvas.Handle, FrameBrokenRect);
end
else
begin
Cursor:=crDefault;
if PtInRect(Rect(Cmr.X,Cmr.Y,Cmr.W,Cmr.H),Point(x,Y)) then
Cursor:=crSizeAll;
if (PtInRect(Cmr.A,Point(x,Y))) or (PtInRect(Cmr.D,Point(x,Y))) then
Cursor:=crSizeNWSE;
if (PtInRect(Cmr.B,Point(x,Y))) or (PtInRect(Cmr.C,Point(x,Y))) then
Cursor:=crSizeNESW;
if (PtInRect(Cmr.AC,Point(x,Y))) or (PtInRect(Cmr.BD,Point(x,Y))) then
Cursor:=crSizeWE;
if (PtInRect(Cmr.AB,Point(x,Y))) or (PtInRect(Cmr.CD,Point(x,Y))) then
Cursor:=crSizeNS;
end;
end;
procedure TNewFrameimage.FrameMouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
CursorRect:TRect;
begin
if MLeftDown then
begin
canvas.FillRect(Rect(0, 0, Width, Height));
TNewimagePanel(Owner).FrameRect:=FrameBrokenRect;
if Assigned(TNewimagePanel(Owner).WatermarkImage) then
begin
TNewimagePanel(Owner).WatermarkImage.Left:=FrameBrokenRect.Left;
TNewimagePanel(Owner).WatermarkImage.Top:=FrameBrokenRect.Top;
end;
MLeftDown:=False;
{ CursorRect:=Rect(0, 0, Screen.Width,Screen.Height);
MapWindowPoints(GetDesktopWindow, 0, CursorRect, 2); // 座标换算
ClipCursor(@CursorRect); // 限制鼠标移动区域 }
end;
end;
{ TNewimagePanel }
procedure TNewimagePanel.CanvasRec(CR: TRect; CCanvas: Tcanvas;Kind:Boolean=true);
var
x,y,w,h:integer;
begin
if Kind then
begin
with CCanvas do
begin
Pen.Color := clNone;
Brush.Color := clNone;
x:=CR.Left;
y:=CR.Top;
w:=CR.Right-CR.Left;
h:=CR.Bottom-CR.Top;
Cmr.X:=x;
Cmr.Y:=y;
Cmr.W:=x+ w;
Cmr.H:=y+h;
FrameRect(CR);
Rectangle(x-3,y-3, X+1,Y+1);
Cmr.A:=Rect(x-3,y-3, X+1,Y+1);
Rectangle(x-3,y+h-1, x+1,y+h+3);
Cmr.C:=Rect(x-3,y+h-1, x+1,y+h+3);
Rectangle(x+w-1,y-3, x+w+3,Y+1);
Cmr.B:=Rect(x+w-1,y-3, x+w+3,Y+1);
Rectangle(x+w-1,y+h-1, x+w+3,y+h+3);
Cmr.D:=Rect(x+w-1,y+h-1, x+w+3,y+h+3);
Rectangle(x-3,y+(h div 2)-2, x+1,y+(h div 2)+2);
Cmr.AC:=Rect(x-3,y+(h div 2)-2, x+1,y+(h div 2)+2);
Rectangle(x+w-1,y+(h div 2)-2, x+w+3,y+(h div 2)+2);
Cmr.BD:=Rect(x+w-1,y+(h div 2)-2, x+w+3,y+(h div 2)+2);
Rectangle(x+(w div 2)-2,y-3, x+(w div 2)+2,Y+1);
Cmr.AB:=Rect(x+(w div 2)-2,y-3, x+(w div 2)+2,Y+1);
Rectangle(x+(w div 2)-2,y+h-1, x+(w div 2)+2,y+h+3);
Cmr.CD:=Rect(x+(w div 2)-2,y+h-1, x+(w div 2)+2,y+h+3);
end;
end
else
begin
with CCanvas do
begin
x:=CR.Left;
y:=CR.Top;
w:=CR.Right-CR.Left;
h:=CR.Bottom-CR.Top;
Cmr.WX:=x;
Cmr.WY:=y;
Cmr.WW:=x+w;
Cmr.WH:=y+h;
Pen.Color := clBlack;
Brush.Color := clBlack;
Pen.Style :=psDash;
Rectangle(x,y, X+4,Y+4);
Cmr.WA:=Rect(x,y, X+4,Y+4);
Rectangle(x,y+h-4, x+4,y+h);
Cmr.WC:=Rect(x,y+h-4, x+4,y+h);
Rectangle(x+w-4,y, x+w,Y+4);
Cmr.WB:=Rect(x+w-4,y, x+w,Y+4);
Rectangle(x+w-4,y+h-4,x+w,y+h);
Cmr.WD:=Rect(x+w-4,y+h-4,x+w,y+h);
Rectangle(x,y+(h div 2)-2, x+4,y+(h div 2)+2);
Cmr.WAC:=Rect(x,y+(h div 2)-2, x+4,y+(h div 2)+2);
Rectangle(x+w-4,y+(h div 2)-2, x+w,y+(h div 2)+2);
Cmr.WBD:=Rect(x+w-4,y+(h div 2)-2, x+w,y+(h div 2)+2);
Rectangle(x+(w div 2)-2,y, x+(w div 2)+2,Y+4);
Cmr.WAB:=Rect(x+(w div 2)-2,y, x+(w div 2)+2,Y+4);
Rectangle(x+(w div 2)-2,y+h-4, x+(w div 2)+2,y+h);
Cmr.WCD:=Rect(x+(w div 2)-2,y+h-4, x+(w div 2)+2,y+h);
// Pen.Mode := pmXOr;
Pen.Style := psDot;
If WatermarkImage.IsClikW then
Pen.Color:=clWhite
else
Pen.Color:=clMedGray;
PolyLine([Point(CR.Left,CR.Top),Point(CR.Left,CR.Bottom-1),Point(CR.Right,CR.Bottom-1)]);
PolyLine([Point(CR.Left,CR.Top),Point(CR.Right-1,CR.Top),Point(CR.Right-1,CR.Bottom-1)]);
end;
end;
end;
constructor TNewimagePanel.Create(Aowner: TComponent);
begin
inherited;
Width:=250;
Height:=50;
Color:=clWindow;
DoubleBuffered:=true;
FPicture := TPicture.Create;
FWatermarkPic:=TPicture.Create;
Newimage:=TNewimage.Create(self);
Newimage.Parent:=self;
Newimage.Align:=alClient;
Newimage.Left:=Left;
Newimage.Top:=Left;
Newimage.Width:=Width;
Newimage.Height:=Height;
Newimage.Center:=true;
NewFrameimage:=TNewFrameimage.Create(self);
NewFrameimage.Parent:=self;
NewFrameimage.Align:=alClient;
NewFrameimage.Left:=Left;
NewFrameimage.Top:=Top;
NewFrameimage.Width:=Width;
NewFrameimage.Height:=Height;
NewFrameimage.Transparent:=true;
NewFrameimage.OnMouseMove:=NewFrameimage.FrameMouseMove;
NewFrameimage.OnMouseDown:=NewFrameimage.FrameMouseDown;
NewFrameimage.OnMouseUp:=NewFrameimage.FrameMouseUp;
end;
destructor TNewimagePanel.Destroy;
begin
inherited;
FPicture.Free;
FWatermarkPic.Free;
WatkBit.Free;
end;
function TNewimagePanel.StretchDraw(BigBmp:TBitmap;Width:Integer;Height:Integer;Edge:Integer):TBitmap;
begin
if (BigBmp.Width<=Width-Edge) and (BigBmp.Height<=Height-Edge) then
begin
Result.Width:=BigBmp.Width;
Result.Height:=BigBmp.Height;
end
else
begin
if (BigBmp.Width<=Width-Edge) and (BigBmp.Height>Height-Edge) then
begin
Result.Width:=Trunc(BigBmp.Width*(Height-Edge)/BigBmp.Height);
Result.Height:=Height-Edge;
end;
if (BigBmp.Height<=Height-Edge) and (BigBmp.Width>Width-Edge) then
begin
Result.Width:=Width-Edge;
Result.Height:=Trunc(BigBmp.Height*(Width-Edge)/BigBmp.Width);
end;
if (BigBmp.Height>Height-Edge) and (BigBmp.Width>Width-Edge) then
begin
if BigBmp.Width>BigBmp.Height then
begin
if BigBmp.Height<Height-Edge then
begin
Result.Width:=Width-Edge;
Result.Height:=Trunc(BigBmp.Height*(Width-Edge)/BigBmp.Width);
end
else
begin
Result.Width:=Trunc(BigBmp.Width*(Height-Edge)/BigBmp.Height);
Result.Height:=Height-Edge;
end;
end;
if BigBmp.Width<BigBmp.Height then
begin
if BigBmp.Width<Width-Edge then
begin
Result.Width:=Width-Edge;
Result.Height:=Trunc(BigBmp.Height*(Width-Edge)/BigBmp.Width);
end
else
begin
Result.Width:=Trunc(BigBmp.Width*(Height-Edge)/BigBmp.Height);
Result.Height:=Height-Edge;
end;
end;
if BigBmp.Width=BigBmp.Height then
begin
Result.Width:=Width-Edge;
Result.Height:=Width-Edge;
end;
end;
end;
Result.Canvas.StretchDraw(Result.Canvas.ClipRect,BigBmp);
end;
procedure TNewimagePanel.Refresh;
var
Buf,BufB,BufC:TBitmap;
begin
Buf:=TBitmap.Create;
BufB:=TBitmap.Create;
BufC:=TBitmap.Create;
WatkBit:=TBitmap.Create;
Buf:=Picture.Bitmap;
if (Buf.Width<=Width-10) and (Buf.Height<=Height-10) then
begin
BufB.Width:=Buf.Width;
BufB.Height:=Buf.Height;
end
else
begin
if (Buf.Width<=Width-10) and (Buf.Height>Height-10) then
begin
BufB.Width:=Trunc(Buf.Width*(Height-10)/Buf.Height);
BufB.Height:=Height-10;
end;
if (Buf.Height<=Height-10) and (Buf.Width>Width-10) then
begin
BufB.Width:=Width-10;
BufB.Height:=Trunc(Buf.Height*(Width-10)/Buf.Width);
end;
if (Buf.Height>Height-10) and (Buf.Width>Width-10) then
begin
if Buf.Width>Buf.Height then
begin
if Buf.Height<Height-10 then
begin
BufB.Width:=Width-10;
BufB.Height:=Trunc(Buf.Height*(Width-10)/Buf.Width);
end
else
begin
BufB.Width:=Trunc(Buf.Width*(Height-10)/Buf.Height);
BufB.Height:=Height-10;
end;
end;
if Buf.Width<Buf.Height then
begin
if Buf.Width<Width-10 then
begin
BufB.Width:=Width-10;
BufB.Height:=Trunc(Buf.Height*(Width-10)/Buf.Width);
end
else
begin
BufB.Width:=Trunc(Buf.Width*(Height-10)/Buf.Height);
BufB.Height:=Height-10;
end;
end;
if Buf.Width=Buf.Height then
begin
BufB.Width:=Width-10;
BufB.Height:=Width-10;
end;
end;
end;
BufB.Canvas.StretchDraw(BufB.Canvas.ClipRect,Buf);
BufC.Width:=Width;
BufC.Height:=Height;
BitBlt(BufC.Canvas.Handle, (Width-BufB.Width) div 2, (Height-BufB.Height) div 2, BufB.Width, BufB.Height, BufB.Canvas.Handle, 0, 0, SRCCOPY);
PicImageRect:=Rect((Width-BufB.Width) div 2,(Height-BufB.Height) div 2,BufB.Width+(Width-BufB.Width) div 2,BufB.Height+(Height-BufB.Height) div 2);
Newimage.Picture.Graphic:=BufC;
BufB.Free;
BufC.Free;
Buf:=nil;
Buf.Free;
end;
procedure TNewimagePanel.ShowWatermark;
var
XRect:TRect;
Buf,BufB,BufC:TBitmap;
Cwidth,CHeight:integer;
begin
Buf:=TBitmap.Create;
BufB:=TBitmap.Create;
BufC:=TBitmap.Create;
WatkBit:=TBitmap.Create;
Buf:=WatermarkPic.Bitmap;
Cwidth:=Width div 4;
CHeight:=Height div 4;
if (Buf.Width<=CWidth) and (Buf.Height<=CHeight) then
begin
BufB.Width:=Buf.Width;
BufB.Height:=Buf.Height;
end
else
begin
if (Buf.Width<=CWidth) and (Buf.Height>CHeight) then
begin
BufB.Width:=Trunc(Buf.Width*(CHeight)/Buf.Height);
BufB.Height:=CHeight;
end;
if (Buf.Height<=CHeight) and (Buf.Width>CWidth) then
begin
BufB.Width:=CWidth;
BufB.Height:=Trunc(Buf.Height*(CWidth)/Buf.Width);
end;
if (Buf.Height>CHeight) and (Buf.Width>CWidth) then
begin
if Buf.Width>Buf.Height then
begin
if Buf.Height<CHeight then
begin
BufB.Width:=CWidth;
BufB.Height:=Trunc(Buf.Height*(CWidth)/Buf.Width);
end
else
begin
BufB.Width:=Trunc(Buf.Width*(CHeight)/Buf.Height);
BufB.Height:=CHeight;
end;
end;
if Buf.Width<Buf.Height then
begin
if Buf.Width<CWidth then
begin
BufB.Width:=CWidth;
BufB.Height:=Trunc(Buf.Height*(CWidth)/Buf.Width);
end
else
begin
BufB.Width:=Trunc(Buf.Width*(CHeight)/Buf.Height);
BufB.Height:=CHeight;
end;
end;
if Buf.Width=Buf.Height then
begin
BufB.Width:=CWidth;
BufB.Height:=CWidth;
end;
end;
end;
BufB.Canvas.StretchDraw(BufB.Canvas.ClipRect,Buf);
// WPicImageRect:=Rect((Width-BufB.Width) div 2,(Height-BufB.Height) div 2,BufB.Width+(Width-BufB.Width) div 2,BufB.Height+(Height-BufB.Height) div 2);
BufC.Width:=BufB.Width+2;
BufC.Height:=BufB.Height+2;
BufC.Canvas.brush.color:=clBlack;
BufC.canvas.FillRect(Rect(0, 0, BufC.Width, BufC.Height));
// BufC.Canvas.FloodFill(0,0,clBlack,fsBorder);
BitBlt(BufC.Canvas.Handle, 1,1,BufB.Width+1, BufB.Height+1, BufB.Canvas.Handle, 0, 0, SRCCOPY);
if not Assigned(WatermarkImage) then
begin
WatermarkImage:=TWatermarkImage.Create(self);
WatermarkImage.Parent:=Self;
WatermarkImage.Left:=PicImageRect.Left-1;
WatermarkImage.Top:=PicImageRect.Top-1;
WatermarkImage.Proportional:=false;
WatermarkImage.Center:=true;
WatermarkImage.OnMouseDown:=WatermarkImage.WFrameMouseDown;
WatermarkImage.OnMouseUp:=WatermarkImage.WFrameMouseUp;
WatermarkImage.OnMouseMove:=WatermarkImage.WFrameMouseMove;
end;
WatermarkImage.Picture.Assign(WatermarkPic);
WatermarkImage.Width:=BufC.Width;
WatermarkImage.Height:=BufC.Height;
WatermarkImage.Picture.Graphic:=BufC;
CanvasRec(Rect(0,0,WatermarkImage.Width,WatermarkImage.Height),WatermarkImage.Canvas,false);
BufB.Free;
Buf:=nil;
Buf.Free;
end;
procedure TNewimagePanel.SetFrameRect(const Value: TRect);
begin
FFrameRect:=Value;
Refresh;
CanvasRec(FFrameRect,Newimage.Canvas);
end;
procedure TNewimagePanel.SetPicture(const Value: TPicture);
begin
FPicture.Assign(Value);
end;
procedure TNewimagePanel.PaintPic(ACanvas: TCanvas; Bitmap: TBitmap); //画透明图标
var
ImageList : TImageList;
TransColor : TColor;
begin
if (Bitmap.Width = 0) or (Bitmap.Height = 0) then
Exit;
TransColor := Bitmap.Canvas.Pixels[0, 5];
ImageList := TImageList.CreateSize(Bitmap.Width, Bitmap.Height);
try
ImageList.AddMasked(Bitmap, TransColor);
ImageList.Draw(ACanvas, 0, 0, 0, Enabled);
finally
ImageList.Free();
end;
end;
procedure TNewimagePanel.FullScreen;
var
Xrect:TRect;
begin
Xrect:=Rect(PicImageRect.Left-1,PicImageRect.Top-1,PicImageRect.Right+1,PicImageRect.Bottom+1);
CanvasRec(Xrect,Newimage.Canvas);
end;
procedure TNewimagePanel.SetWatermarkPic(const Value: TPicture);
begin
FWatermarkPic.Assign(Value);
end;
{ TWatermarkImage }
constructor TWatermarkImage.Create(Aowner: TComponent);
begin
inherited;
end;
destructor TWatermarkImage.Destroy;
begin
inherited;
end;
procedure TWatermarkImage.WFrameMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
IsClikW:=True;
TNewimagePanel(Owner).ShowWatermark;
WMPoint:=Point(x,y);
if (PtInRect(Cmr.WA,Point(x,Y))) or (PtInRect(Cmr.WAB,Point(x,Y))) or (PtInRect(Cmr.WB,Point(x,Y)))
or (PtInRect(Cmr.WAC,Point(x,Y))) then
MUp:=true
else
MUp:=false
end;
procedure TWatermarkImage.WFrameMouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
begin
if IsClikW and ( ssleft in shift ) then
begin
if Cursor=crSizeAll then
begin
left:=left+x-WMPoint.x;
Top:=top+Y-WMPoint.Y;
if Left<TNewimagePanel(Owner).FrameRect.Left then
left:=TNewimagePanel(Owner).FrameRect.Left;
if Top<TNewimagePanel(Owner).FrameRect.Top then
Top:=TNewimagePanel(Owner).FrameRect.Top;
if Left+width>TNewimagePanel(Owner).FrameRect.Right then
Left:=TNewimagePanel(Owner).FrameRect.Right-width;
if Top+Height>TNewimagePanel(Owner).FrameRect.Bottom then
Top:=TNewimagePanel(Owner).FrameRect.Bottom-Height;
end;
if Cursor=crSizeNWSE then
begin
if MUp then
begin
left:=left+(x-WMPoint.x);
Top:=top+(Y-WMPoint.Y);
end
else
begin
left:=left+x-WMPoint.x;
Top:=top+Y-WMPoint.Y;
end;
end;
end
else
begin
Cursor:=crDefault;
if PtInRect(Rect(Cmr.WX,Cmr.WY,Cmr.WW,Cmr.WH),Point(x,Y)) then
Cursor:=crSizeAll;
if (PtInRect(Cmr.WA,Point(x,Y))) or (PtInRect(Cmr.WD,Point(x,Y))) then
Cursor:=crSizeNWSE;
if (PtInRect(Cmr.WB,Point(x,Y))) or (PtInRect(Cmr.WC,Point(x,Y))) then
Cursor:=crSizeNESW;
if (PtInRect(Cmr.WAC,Point(x,Y))) or (PtInRect(Cmr.WBD,Point(x,Y))) then
Cursor:=crSizeWE;
if (PtInRect(Cmr.WAB,Point(x,Y))) or (PtInRect(Cmr.WCD,Point(x,Y))) then
Cursor:=crSizeNS;
end;
end;
procedure TWatermarkImage.WFrameMouseUp(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
IsClikW:=false;
end;
end.