怎样使用Canvas(50分)

  • 主题发起人 主题发起人 yukaikai
  • 开始时间 开始时间
Y

yukaikai

Unregistered / Unconfirmed
GUEST, unregistred user!
使用以下代码抓屏幕,想在上面做简单处理,比如:加文字等,但是总是没有效果,为什么?谢谢回答!
procedure TEPCSnapScrn.SnapScrn(LeftPos,TopPos,RightPos,BottomPos:integer;VFIleName:String);
var
RectWidth,RectHeight:integer;
SourceDC,DestDC,Bhandle:integer;
Bitmap:TBitmap;
BmpStream:TFileStream;
LeftSize:Integer;
R:TRect;
begin
RectWidth:=RightPos-LeftPos;
RectHeight:=BottomPos-TopPos;
SourceDC:=CreateDC('DISPLAY','','',nil);
DestDC:=CreateCompatibleDC(SourceDC);
Bhandle:=CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight);
SelectObject(DestDC,Bhandle);
BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY);
Bitmap:=TBitmap.create;
Bitmap.Handle:=BHandle;

BitMap.Canvas.Pen.Color:=clYellow;
R:=Rect(20,20,500,500);
Bitmap.Canvas.Chord(R.Left, R.Top, R.Right, R.Bottom, R.Right, R.Top, R.Left, R.Top);
Bitmap.SaveToFile(VFileName);
Bitmap.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);
end;
 
怎么没有朋友回答呢?
是不是问题太简单?
 
//老大,好厉害啊, 有东西啊[^]
unit Unit1;

interface

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

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
procedure SnapScrn(LeftPos,TopPos,RightPos,BottomPos:integer;VFIleName:String);
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SnapScrn(LeftPos,TopPos,RightPos,BottomPos:integer;VFIleName:String);
var
RectWidth,RectHeight:integer;
SourceDC,DestDC,Bhandle:integer;
Bitmap:TBitmap;
BmpStream:TFileStream;
LeftSize:Integer;
R:TRect;
begin
RectWidth:=RightPos-LeftPos;
RectHeight:=BottomPos-TopPos;
SourceDC:=CreateDC('DISPLAY','','',nil);
DestDC:=CreateCompatibleDC(SourceDC);
Bhandle:=CreateCompatibleBitmap(SourceDC,RectWidth,RectHeight);
SelectObject(DestDC,Bhandle);
BitBlt(DestDC,0,0,RectWidth,RectHeight,SourceDC,LeftPos,TopPos,SRCCOPY);
Bitmap:=TBitmap.create;
Bitmap.Handle:=BHandle;

BitMap.Canvas.Pen.Color:=clYellow;
R:=Rect(20,20,500,500);
Bitmap.Canvas.Chord(R.Left, R.Top, R.Right, R.Bottom, R.Right, R.Top, R.Left, R.Top);
Bitmap.SaveToFile(VFileName);
Bitmap.Free;
DeleteDC(DestDC);
ReleaseDC(Bhandle,SourceDC);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
SnapScrn(10, 10, 100, 100, 'c:/scrn.bmp');
end;

end.
 
你用的是delphi几啊
 
问题结束
散分
 
后退
顶部