Re:Resizing a larger rectangle to fit in a smaller one.
On Wed, 09 Dec 1998 11:12:17 -0500, "Jon E. Scott"
Quote
<jsc...@landstar.com> wrote:
>Currently I am using a whole bunch of if..then statements to compare the
>width and height of the two rectangles and determining the scaling
>factor by dividing the original rect size (width or height) by the
>second rect size. If the second is smaller than the first, the scaling
>factor is 1.
>There MUST be a better way and I'm thinking StretchDIBits() but don't
>quite know how to use it. Remember, I am trying to reduce the rectangle
>size while keeping the aspect ratio.
Even using StretchDIBits, you have to calculate the scaling factor.
But it's really not that difficult:
var
XScale: Single;
YScale: Single;
Scale: Single;
begin
XScale := 1.0;
YScale := 1.0;
if TargetWidth < SourceWidth then
XScale := TargetWidth / SourceWidth;
if TargeeHeight < SourceHeight then
YScale := TargetHeight / SourceHeight;
Scale := XScale;
if YScale < Scale then
Scale := YScale;
end;
Now use Scale as your scaling factor.
-Steve