delphi - 在lazarus或delphi中调整图像大小?

标签 delphi screenshot desktop pascal lazarus

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

最佳答案

将 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.

关于delphi - 在lazarus或delphi中调整图像大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17206156/

相关文章:

javascript - 带 JavaScript 客户端的 Delphi 服务器

delphi - "var"在字段声明上有什么区别?

MySQL : start Transaction if a condition was true

delphi - 更改 Firemonkey TListView 中的交替颜色

android - 如何防止 Android 或 React-Native 应用程序中的屏幕截图

windows-phone-7 - 我们可以使用 Blackberry 和 Windows 7 SDK 以编程方式截取屏幕截图吗?

node.js - Node-webkit 桌面应用程序限制

python - 在 pyautogui 中保存热键屏幕截图

基于 linux 终端的桌面

macos - 保存整个桌面状态?