Reputation: 610
I am currently making a desktop screenshot in pascal
using lazarus
, I have the screenshot working but it only shows the top left of the desktop. I have it set to display smaller image of the desktop on a TImage
. I tried using MyBitmap.width := Round(370)
and MyBitmap.Height := Round(240);
But those did not work.
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.
Upvotes: 1
Views: 6602
Reputation: 27377
Replace LoadFromDevice with
MyBitmap.SetSize(370, 240);
StretchBlt(MyBitmap.Canvas.Handle, //destination HDC
0, 0, 370, 240, // destination size
ScreenDC, //source HDC
0, 0, Screen.Width, Screen.Height, // source size
SrcCopy
);
Setting a smaller size on an existing Bitmap will just crop it.
Your intention is to scale the bitmap.
Upvotes: 4