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 创建圆形或椭圆形窗体

Delphi 组件篇 之 tbevel组件

Delphi 10.3 断点调试相关快捷键

比cmd更强大的命令行wmic

Delphi 通过wmi获取u盘硬件特征码

Delphi 压缩图片算法

Delphi通过url获取网页源码

Delphi tdictionary 泛型如何排序

Delphi sccoloredid,星际争霸彩色 id 修改器 v0.2.0,支持 windows vista

Delphi datasnap的线程池

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



打赏

取消

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

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

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

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

评论

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