AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Multimedia Delphi Compute screen proportion
Thema durchsuchen
Ansicht
Themen-Optionen

Compute screen proportion

Ein Thema von WojTec · begonnen am 21. Jul 2012 · letzter Beitrag vom 24. Jul 2012
Antwort Antwort
freeway

Registriert seit: 11. Jul 2009
57 Beiträge
 
Delphi XE Professional
 
#1

AW: Compute screen proportion

  Alt 21. Jul 2012, 21:25
first part of your question, i realy don´t understand ???

work with fractions
http://en.wikipedia.org/wiki/Fraction_(mathematics)
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#2

AW: Compute screen proportion

  Alt 22. Jul 2012, 07:05
Do you know the difference between display resolution and aspect ratio? Why do you name your thread 'screen proportion' but you refer to images?
Did you bother using google?
I found all answers.

But what the heck:

Most modern screen resulutions are not exactly 16:9, 4:3 etc.

I would recommend using a list of standard ratios, e.g. (4:3, 5:4, 16:9, 16:10), compare the screen dimension (widht / height) with the entries in the list and return the closest candidate or 'none' if the difference is out of tolerance.

Delphi-Quellcode:
Function AspectRatio (aWidth, aHeight : Integer) : String;
Const
  RatioX : Array [0..3] of integer = (4,5,16,16);
  RatioY : Array [0..3] of integer = (3,4,10, 9);

  tolerance = 1E-2;

Var
  diff,dmin, ratio : Double;
  i,j : Integer;

Begin
  ratio := aWidht/aHeight;
  dmin := 999;
  j:=-1;
  for i:=0 to High(RatioX) do begin
    diff := abs(RatioX[i]/RatioY[i] - ratio);
    if diff < dmin then begin
      j := i;
      dmin := diff;
    end
  end;

  if diff<tolerance then
     result := Format('%d:%d',[RatioX[j], RatioY[j]])
  else
     result := 'nonstandard';
End;
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#3

Re: Compute screen proportion

  Alt 22. Jul 2012, 08:50
Thanks, but for eg. 1024x768 returns 'nonstandard'
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#4

AW: Compute screen proportion

  Alt 22. Jul 2012, 11:01
The code is untested.

What would you do go make it work?
Do you understand the Code?
  Mit Zitat antworten Zitat
Amateurprofi

Registriert seit: 17. Nov 2005
Ort: Hamburg
1.111 Beiträge
 
Delphi XE2 Professional
 
#5

AW: Compute screen proportion

  Alt 22. Jul 2012, 11:45
This should work:

Delphi-Quellcode:
FUNCTION AspectRatio(width,height:Integer):String;
FUNCTION LCD(v1,v2:integer):integer;
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:integer; s:string;
begin
   divisor:=LCD(width,height);
   if divisor=0 then result:='Width or Height <= 0'
      else result:=IntToStr(width div divisor)+':'+IntToStr(height div divisor);
end;
Gruß, Klaus
Die Titanic wurde von Profis gebaut,
die Arche Noah von einem Amateur.
... Und dieser Beitrag vom Amateurprofi....
  Mit Zitat antworten Zitat
Furtbichler
(Gast)

n/a Beiträge
 
#6

AW: Compute screen proportion

  Alt 22. Jul 2012, 11:53
The GCD of 1366 x 768 is 2. However these displays are treated as 16:9.
  Mit Zitat antworten Zitat
WojTec

Registriert seit: 17. Mai 2007
482 Beiträge
 
Delphi XE6 Professional
 
#7

Re: Compute screen proportion

  Alt 22. Jul 2012, 19:14
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
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:17 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz