【问题标题】:Resize image in lazarus or delphi?在拉撒路或德尔福调整图像大小?
【发布时间】:2013-06-20 05:46:54
【问题描述】:

我目前正在使用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. 

【问题讨论】:

标签: delphi screenshot desktop pascal lazarus


【解决方案1】:

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

【讨论】:

  • 哦,太好了,我有两个问题。 1.为什么用这个替换loadfromdevice。 2. 链接将更详细地使用stretchblt,所以我知道额外的0 是什么意思。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-17
  • 2012-12-13
  • 2014-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多