【发布时间】:2013-06-20 05:46:54
【问题描述】:
我目前正在使用lazarus 在pascal 中制作桌面截图,我的截图工作正常,但它只显示桌面的左上角。我将其设置为在TImage 上显示较小的桌面图像。我尝试使用MyBitmap.width := Round(370) 和MyBitmap.Height := Round(240);
但这些都不起作用。
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, LCLIntf, LCLType;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
MyBitmap : Tbitmap;
ScreenDC: HDC;
begin
try
MyBitmap := TBitmap.Create;
ScreenDC := GetDC(0);
MyBitmap.LoadFromDevice(ScreenDC);
MyBitmap.Width := Round(370);
Mybitmap.Height := Round(240);
ReleaseDC(0, ScreenDC);
Image1.Picture.Bitmap.Assign(MyBitmap);
finally
MyBitmap.free;
end;
end;
end.
【问题讨论】:
-
那么会发生什么?你原来的 MyBitmap 只有桌面的一部分吗?哪一部分?或者您在调整大小后生成的位图是否仅包含原始位图的一部分?为什么你在那里使用 Round 函数?顺便说一句,这是在网络搜索中搜索您的问题的第三个结果:tek-tips.com/viewthread.cfm?qid=81626
-
对不起,我忘了说我的 TImage 比图像的实际尺寸小,但是,bummi 解决了这个问题。
标签: delphi screenshot desktop pascal lazarus