Hi folks,
using Transform (see i.e. www.bobpowell.net/bestfit.htm) I'm drawing a
scaled version of an image onto a panel (code s.b.).
Any pointers as to how to get the size and position after the transform?
Using something like this (with the code below) ...
rectScaled = New Rectangle( _
CType(sngPosX, Integer), _
CType(sngPosY, Integer), _
ctlContainer.Width - CType(sngPosX * 2, Integer), _
ctlContainer.Height - CType(sngPosY * 2, Integer))
.... will work for images being wider than high but not vice versa.
I just don't get it. :-(
TIA,
Olaf
--
Code:
--- 8< ---
Dim dblLargestRatio As Double = _
Math.Max( _
CType(img.Width, Double) / ctlContainer.Width, _
CType(img.Height, Double) / ctlContainer.Height)
Dim sngPosX As Single = _
CType((ctlContainer.Width * dblLargestRatio / 2) - _
(img.Width / 2), Single)
Dim sngPosY As Single = _
CType((ctlContainer.Height * dblLargestRatio / 2) - _
(img.Height / 2), Single)
dim m as New Matrix(1 / CType(dblLargestRatio, Single), 0, 0, _
1 / CType(dblLargestRatio, Single), 0, 0)
m.Translate(sngPosX, sngPosY)
e.Graphics.Transform = m
e.Graphics.DrawImageUnscaled(img, 0, 0)