Resize / Scale and image proportionately
public Size ScaleImage( Size imgToResize, Size size )
{
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;
int oldWIdth = size.Width;
int oldHeight = size.Height;
float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;
nPercentW = ( ( float )oldWIdth / ( float )sourceWidth );
nPercentH = ( ( float )oldHeight / ( float )sourceHeight );
if ( oldWIdth > oldHeight )
nPercent = nPercentW;
else
nPercent = nPercentH;
int destWidth = ( int )( oldWIdth / nPercent );
int destHeight = ( int )( oldHeight / nPercent );
return new Size( destWidth, destHeight );
}
Comments
Post a Comment