[delphi]一毫米等于多少像素? – GetDeviceCaps

  • A+
所属分类:[开发技巧]

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
mmW,mmH: Integer;
pixW,pixH: Integer;
pm: Double;
begin
{以毫米为单位获取屏幕尺寸}
mmW := GetDeviceCaps(Canvas.Handle, HORZSIZE);
mmH := GetDeviceCaps(Canvas.Handle, VERTSIZE);
ShowMessageFmt('屏幕宽: %d 毫米; 屏幕高: %d 毫米', [mmW, mmH]);
{屏幕宽: 320 毫米; 屏幕高: 240 毫米}

{以像素为单位获取屏幕尺寸}
pixW := GetDeviceCaps(Canvas.Handle, HORZRES);
pixH := GetDeviceCaps(Canvas.Handle, VERTRES);
ShowMessageFmt('屏幕宽: %d 像素; 屏幕高: %d 像素', [pixW, pixH]);
{屏幕宽: 1024 像素; 屏幕高: 768 像素}

{当前状态下, 1 毫米等于多少像素?}
ShowMessage(FloatToStr(pixW / mmW)); {3.2}
ShowMessage(FloatToStr(pixH / mmH)); {3.2}

{一步获取}
pm := GetDeviceCaps(Canvas.Handle, HORZRES) / GetDeviceCaps(Canvas.Handle, HORZSIZE);
ShowMessage(FloatToStr(pm)); {3.2}
end;

end.
--------------------------------------------------------------------------------

  • 我的微信
  • 这是我的微信扫一扫
  • weinxin
  • 我的微信公众号
  • 我的微信公众号扫一扫
  • weinxin
广告也精彩
avatar
广告也精彩

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: