![]() |
Delphi-Version: 10 Berlin
Fit image in control
Delphi-Quellcode:
Samples:
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; 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? |
AW: Fit image in control
Seems like you want to keep the aspect ratio of the media when stretching into the control. In that case you will most likely end up with the media not filling the control completely. As the aspect ratio of the media and the control differ slightly, there is not much you can do about it.
|
Re: Fit image in control
Yes, but in examples both ratios are 16:9, it shouldn't be streched (of course only in case if both has the same aspect ratio, for example HD/FullHD/UltraHD stream on wide screen)?
|
AW: Fit image in control
Maybe this helps to make calculations easier, if this is what you are looking for.
FitInto and PlaceInto are nice functions already in the library, but not very popular. Zitat:
![]() Rollo |
AW: Re: Fit image in control
Zitat:
|
Re: Fit image in control
Ok, I understand, thank you :)
But another question is, if above code is oke, why eg. Photoshop has different result for this data? |
AW: Fit image in control
Could be a rounding error. Try another formula:
Delphi-Quellcode:
Result.Width := Round(AMediaWidth * AControlHeight / AMediaHeight);
and
Delphi-Quellcode:
Result.Height := Round(AMediaHeight * AControlWidth / AMediaWidth);
Your Version defines a small result in your term to round, leading to a possible inaccuracy with your following multipication. Second: Round uses Banker's Rounding. If your term to round is in the middle of two numbers it will give you the even number. Gretings Mikhal |
Re: Fit image in control
Also returns one line not enough :(
|
AW: Re: Fit image in control
Zitat:
|
Re: Fit image in control
Yeah, what is different way to do this?
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:44 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 by Thomas Breitkreuz