Einzelnen Beitrag anzeigen

WojTec

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

Fit image in control

  Alt 31. Jan 2017, 20:51
Delphi-Version: 10 Berlin
Delphi-Quellcode:
        ScaleX := AControlWidth / AMediaWidth;
        ScaleY := AControlHeight / AMediaHeight;

        if ScaleX >= ScaleY then
        begin
// Result.Width := Round(AMediaWidth * ScaleY);
          Result.Width := Round((AMediaWidth / AMediaHeight) * AControlHeight);
          Result.Height := AControlHeight;
        end
        else
        begin
          Result.Width := AControlWidth;
          Result.Height := Round((AMediaHeight / AMediaWidth) * AControlWidth);
// Result.Height := Round(AMediaHeight * ScaleX);
        end;
Samples:
1920, 1080, 1366, 768 = 1365, 768
1366, 768, 1920, 1080 = 1920, 1079

So, in both variants (commented and not) result is the same (code based on GR32.GetBitmapSize) - is one line not enough in width or height. How to fix it? Something like add one and check range?
  Mit Zitat antworten Zitat