调整拉撒路或德尔福的图像大小?

时间:2013-06-20 05:46:54

标签: delphi screenshot desktop pascal lazarus

我目前正在使用pascallazarus制作桌面屏幕截图,我有截图工作但它只显示桌面的左上角。我将它设置为在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. 

1 个答案:

答案 0 :(得分:4)

将LoadFromDevice替换为

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 
  );

在现有位图上设置较小的尺寸只会裁剪它 您的目的是缩放位图。

The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle, stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context.