Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting the image width and height automatically keeping aspect ratio

Status
Not open for further replies.

Adin0605

Technical User
Sep 11, 2009
3
0
0
DE
Hi there,

I have an image uploaded on the website, and I want to generate width and height automatically from a given values(image values in cm).

Ex:
' Image values in cm
Dim strInal as string = 140
Dim strLati as string = 90

Dim strRatio As String
Dim cnstInaltime As Integer
Dim cnstLatime As Integer

' checking to see the image format

If strInal.ToString > strLati.ToString Then
strRatio = Math.Round(strInal / strLati)
cnstInaltime = 15
cnstLatime = 10 * strRatio
End If
If strInal.ToString = strLati.ToString Then
strRatio = 1
cnstInaltime = 5
cnstLatime = 5
End If
If strLati.ToString > strInal.ToString Then
strRatio = Math.Round(strLati / strInal)
cnstInaltime = 10 * strRatio
cnstLatime = 15
End If

Dim intA As Integer = strInal
Dim intB As Integer = strLati

' generating the values in decreasing way

While (intA > 15 Or intB > 15)

intA -= cnstInaltime
intB -= cnstLatime
End While


The code above cannot keep aspect ratio. Can someone help me?
Thanks

 
Ok, my guess is that you are not really understanding what you are trying to do.

Code:
Dim strInal as string = 140
Dim strLati as string = 90
...
      If strInal.ToString > strLati.ToString Then

If strInal is a string as you have defined at the top, then why call ToString on it again ?

Put breakpoints in the code and step through, see what is really happening.
 
Thanks, you're wrong. MAy be I didn't explained but the code should explain himself.
What I want to achieve is the resize of an image while kepping aspect ratio of that image.
My code is running well, the only problem is that I dont know what formula I should apply to have a decent image height and a decent image width.

The conditional statement is wrong as the 2 values must compare while are integers.

So,

Dim strInal as Integer = 140
Dim strLati as Integer = 90

Dim strRatio As String
Dim cnstInaltime As Integer
Dim cnstLatime As Integer

' checking to see the image format

If strInal > strLati Then
strRatio = Math.Round(strInal / strLati)
cnstInaltime = 15
cnstLatime = 10 * strRatio
End If
If strInal = strLati Then
strRatio = 1
cnstInaltime = 5
cnstLatime = 5
End If
If strLati > strInal Then
strRatio = Math.Round(strLati / strInal)
cnstInaltime = 10 * strRatio
cnstLatime = 15
End If

Dim intA As Integer = strInal
Dim intB As Integer = strLati

' generating the values in decreasing way

While (intA > 15 Or intB > 15)

intA -= cnstInaltime
intB = intA * strRatio
End While


As I said the code it's ok, but the values are not, and I cannot figure out how to keep aspect ratio.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top