Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Multimedia (https://www.delphipraxis.net/16-multimedia/)
-   -   Delphi Compute screen proportion (https://www.delphipraxis.net/169462-compute-screen-proportion.html)

Furtbichler 22. Jul 2012 11:53

AW: Compute screen proportion
 
The GCD of 1366 x 768 is 2. However these displays are treated as 16:9.

WojTec 22. Jul 2012 19:14

Re: Compute screen proportion
 
I modified @Amateurprofi code to support x:10, changed to return float and wrote format function:

Delphi-Quellcode:
function GetScreenProportion(const AWidth, AHeight: Cardinal): string;
var
  AspectRatio: Single;
  X, Y: Extended;
begin
  AspectRatio := GetScreenAspectRatio(AWidth, AHeight);
  X := Int(AspectRatio);
  Y := Frac(AspectRatio) * 100;

  if Int(Y) <> 10 then
    Y := Y / 10
  ;

  Result := Format('%.0f:%.0f', [X, Y])
end;
Thanks :-D

Furtbichler 22. Jul 2012 22:42

AW: Compute screen proportion
 
Please post the code for "GetScreenAspectRatio".

WojTec 23. Jul 2012 10:03

Re: Compute screen proportion
 
Here you are :)

Delphi-Quellcode:
function GetScreenAspectRatio(const AWidth, AHeight: Cardinal): Single;

function LCD(v1, v2: Cardinal): Word;
begin
  Result := 0;

  if (v1 > 0) and (v2 > 0) then
  begin
    repeat
      Result := v1 mod v2;
      v1 := v2;
      v2 := Result;
    until v2 = 0;

    Result := v1;
  end;
end;

var
  Divisor: Word;
  X, Y: Cardinal;
begin
  Result := 0;
  Divisor := LCD(AWidth, AHeight);

  if Divisor <> 0 then
  begin
    X := AWidth div Divisor;
    Y := AHeight div Divisor;

    if (X = 8) and (Y = 5) then
    begin
      X := X * 2;
      Y := Y * 2;
    end;

    Result := IFF(Y <> 10, X + (Y / 10), X + (Y / 100));
  end;
end;
IFF routine you can get here (requires this).

Furtbichler 23. Jul 2012 11:23

AW: Compute screen proportion
 
What's the result with my laptop's resolution (1366 x 768)? It should be 16:9.

WojTec 23. Jul 2012 13:18

Re: Compute screen proportion
 
Hm, it's a bit wrong (721:4) :o

Furtbichler 23. Jul 2012 13:30

AW: Compute screen proportion
 
You see? Use my attempt and use a higher tolerance.

Sir Rufo 23. Jul 2012 13:40

AW: Compute screen proportion
 
Zitat:

Zitat von Furtbichler (Beitrag 1175662)
You see? Use my attempt and use a higher tolerance.

No, your laptop has a bad physical design. It has 2/3 pixels to much in width :mrgreen:

WojTec 23. Jul 2012 17:46

Re: Compute screen proportion
 
@Furtbichler, I tested a few inputs and I see 0.45 is ok. Could you confirm?

Furtbichler 24. Jul 2012 05:26

AW: Compute screen proportion
 
Check for yourself. To make things a bit more complicated, the link introduces pixel aspect ratio and display aspect ratio.
Zitat:

Zitat von Sir Rufo (Beitrag 1175668)
No, your laptop has a bad physical design. It has 2/3 pixels to much in width :mrgreen:

Damned. Thanks god I own a jigsaw. Let me get it and cut off tho


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:12 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz