delphi 模仿QQ截图


本文整理自网络,侵删。

 unit UnitCutPic;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TFrmCutPic = class(TForm)
SaveDPic: TSaveDialog;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure FormKeyPress(Sender: TObject; var Key: Char);
private
procedure SnapScreen(a, b, c, d: Integer; Apath: string);
{ Private declarations }
public
{ Public declarations }
end;

var
FrmCutPic: TFrmCutPic;
BeginX,BeginY,Endx,EndY:integer;//全局变量 记录鼠标按下时的X,Y坐标
IsPoint:Boolean;
point:Tpoint;
Arect:TRect;
implementation

{$R *.dfm}

procedure TFrmCutPic.SnapScreen(a,b,c,d:Integer;Apath:string); //任意区域截图,参数为截图坐标
var
bmpscreen:Tbitmap;
FullscreenCanvas:TCanvas;
dc:HDC;
sourceRect, destRect: TRect;
begin
dc:=getdc(0);
fullscreencanvas:=Tcanvas.Create;
fullscreencanvas.Handle:=dc;
bmpscreen:=Tbitmap.create;
bmpscreen.Width :=c-a;
bmpscreen.Height :=d-b;
sourcerect:=Rect(0,0,c-a ,d-b );
destrect:= Rect(a,b,c,d);
bmpscreen.Canvas.CopyRect(sourcerect,fullscreenCanvas,destrect);
bmpscreen.SaveToFile(Apath);
FullscreenCanvas.Free;
bmpscreen.Free;
ReleaseDC(0, DC);
end;

procedure TFrmCutPic.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ssright in shift then Self.Close;
if (IsPoint=True) and (ssleft in shift) and (ssDouble in Shift)then
begin
GetCursorPos(point);
if PtInRect(Arect,point)=True then
begin
SnapScreen(Arect.Left,Arect.Top,Arect.Right,Arect.Bottom,ExtractFilePath(Application.ExeName)+'\Cut.bmp');
if not SaveDPic.Execute then
begin
DeleteFile(ExtractFilePath(Application.ExeName)+'\Cut.bmp');
Exit;
end;
CopyFile(PChar(ExtractFilePath(Application.ExeName)+'\Cut.bmp'),PChar(SaveDPic.FileName),False);
DeleteFile(ExtractFilePath(Application.ExeName)+'\Cut.bmp');
Self.Close;
end;
end;
BeginX:=X;BeginY:=Y;//记录鼠标按下时的X,Y坐标
end;

procedure TFrmCutPic.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
GetCursorPos(point);
if (PtInRect(Arect,point)=True) then
Cursor:=crSizeAll
else
Cursor:=crCross;


//下面代码演示的是背景为纯色时的选取框.
//选取的范围可记录在一个TRECT变量里.具体情况视要求而定.
//当背影为图形时..可以把注释1之间的代码替换为重绘背景的代码
if ssLeft in shift then//判断鼠标左键是下按着.
begin
Canvas.Brush.Color:=RGB(255,255,255);
Canvas.Brush.Style:=bsSolid;
Canvas.FillRect(RECT(0,0,width,height));
Canvas.Brush.Style:=bsClear;
Canvas.Pen.Style:=psDot;
Canvas.Pen.Width:=2;
Canvas.Pen.Color:=clBlue;
Canvas.Rectangle(BeginX,BeginY,X,Y);
Arect.Left:=BeginX;
Arect.Top:=BeginY;
Arect.Right:=x;
Arect.Bottom:=y;
endx:=x;
endy:=y;
IsPoint:=True;
end;
end;

procedure TFrmCutPic.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key = #27 then application.terminate;
end;

end.

相关阅读 >>

Delphi动态创建一个ipedit控件

Delphi 本地数据库备份与还原(Delphi)

Delphi 动态给combobox赋值,从combobox中取值

Delphi ascii 码对照表

Delphi入门语法

Delphi d10.x 在安卓app开发中使用jar包的注意事项

Delphi xe5 手机应用开发经验技巧

Delphi 如何识别应用程序没有响应

Delphi判断不同格式的时间是否相等

Delphi弹出信息框大全

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...