user736893
user736893

Reputation:

vb.net multiple pictureBoxes, same width, maintain aspect ratio

I have a global variable called fWidth that is currently 300.

I'm setting pictureBox.width = fWidth, but then I want to do something like pictureBox.height = calcImgHeight(originalHeight,originalWidth)

This is where the problem comes in, because I'm terrible at math :D

Private Function calcImgHeight(oHeight, oWidth)
    Dim nHeight, ratio As Integer
    ratio = oWidth / fWidth
    nHeight = oHeight / ratio

    Return nHeight
End Function

What should the correct code be?

Upvotes: 1

Views: 372

Answers (1)

DavidB
DavidB

Reputation: 2596

I bet I'm worse at maths than you, but fortunately I'm good at Googling.

http://andrew.hedges.name/experiments/aspect_ratio/

original height / original width x new width = new height

Upvotes: 1

Related Questions