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!

Can't resize image files proportionally.

Status
Not open for further replies.

JimboD

Programmer
Jul 14, 2005
6
0
0
US
Hi all I have a form on my site that my visitors use to upload pictures that are used on another page. The pictures are sent to an image file and the pic name is stored on a Access database. I have the pictures (5 of them) uploading and sent to the DB and file and all works fine. The only problem is that sometimes the pictures are distorted or way to big. I need to be able to re size them proportionally based on the width. I have tryed a bunch of things and had no luck. I have a set of radio buttons and a bunch of other stuf on the page but I cant seam to be able to figure out what the code to do this is and where to put it. Below is the code I have that works.
Can anybody help me?


Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
getconfiguration()
End If

Pic1.ImageUrl = url & "\images\" & saveimage1
Image1.ImageUrl = url & "\images\" & saveimage1
Image2.ImageUrl = url & "\images\" & saveimage2
Image3.ImageUrl = url & "\images\" & saveimage3
Image4.ImageUrl = url & "\images\" & saveimage4
Image5.ImageUrl = url & "\images\" & saveimage5

End Sub
Private Sub getconfiguration()
'Dim pathstring As String

Dim sql As String = "SELECT Configuration.URL, Configuration.Picture1, Configuration.Picture2, Configuration.Picture3, Configuration.Picture4, Configuration.Picture5, Configuration.Picture6, Configuration.Picture7, Configuration.Picture8, Configuration.Picture9, Configuration.Picture10, Configuration.EntityName FROM Configuration;"
Cn.ConnectionString = conn
Cn.Open()
Dim cmd As New OleDbCommand(sql, Cn)
Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.SingleResult)
Try
Do While dr.Read
If Not IsDBNull(dr.Item("Url")) Then
url = dr.Item("Url")
End If
If Not IsDBNull(dr.Item("Picture1")) Then
saveimage1 = dr.Item("Picture1")
End If
If Not IsDBNull(dr.Item("picture2")) Then
saveimage2 = dr.Item("Picture2")
End If
If Not IsDBNull(dr.Item("picture3")) Then
saveimage3 = dr.Item("Picture3")
End If
If Not IsDBNull(dr.Item("picture4")) Then
saveimage4 = dr.Item("Picture4")
End If
If Not IsDBNull(dr.Item("picture5")) Then
saveimage5 = dr.Item("Picture5")
End If
If Not IsDBNull(dr.Item("entityname")) Then
EntityName = dr.Item("EntityName")
End If

Loop

Catch ex As OleDbException
Finally
dr.Close()
Cn.Close()
End Try

End Sub

Private Sub CmdUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdUpload.Click
Dim myfield As String

If RBL.Items(0).Selected = True Then
myfield = "Picture1"
ElseIf RBL.Items(1).Selected = True Then
myfield = "Picture2"
ElseIf RBL.Items(2).Selected = True Then
myfield = "Picture3"
ElseIf RBL.Items(3).Selected = True Then
myfield = "Picture4"
ElseIf RBL.Items(4).Selected = True Then
myfield = "Picture5"
End If

If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("Images") & "\" & fn
Try
Kill(Server.MapPath("Images" & "\" & fn))
Catch
End Try
Try
File1.PostedFile.SaveAs(SaveLocation)
Catch Exc As Exception
End Try
End If

Dim myfile As String = File1.PostedFile.FileName
Dim a As Int16
For a = Len(myfile) To 1 Step -1
If Mid$(myfile, a, 1) = "\" Then
myfile = Mid$(myfile, a + 1, Len(myfile) - a)
a = 1
End If
Next

Select Case myfield
Case "Picture1" : Image1.ImageUrl = Server.MapPath("images") & myfile
Pic1.ImageUrl = Server.MapPath("images") & myfile
saveimage1 = myfile
Case "Picture2" : Image2.ImageUrl = Server.MapPath("images") & myfile
saveimage2 = myfile
Case "Picture3" : Image3.ImageUrl = Server.MapPath("images") & myfile
saveimage3 = myfile
Case "Picture4" : Image4.ImageUrl = Server.MapPath("images") & myfile
saveimage4 = myfile
Case "Picture5" : Image5.ImageUrl = Server.MapPath("images") & myfile
saveimage5 = myfile
End Select

Pic1.ImageUrl = url & "\images\" & saveimage1
Image1.ImageUrl = url & "\images\" & saveimage1
Image2.ImageUrl = url & "\images\" & saveimage2
Image3.ImageUrl = url & "\images\" & saveimage3
Image4.ImageUrl = url & "\images\" & saveimage4
Image5.ImageUrl = url & "\images\" & saveimage5

End Sub

Private Sub CmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdApply.Click
Dim sql As String

sql = "UPDATE Configuration SET Configuration.Picture1 = '" & saveimage1 & "', Configuration.Picture2 = '" & saveimage2 & "', Configuration.Picture3 = '" & saveimage3 & "', Configuration.Picture4 = '" & saveimage4 & "', Configuration.Picture5 = '" & saveimage5 & "';"
Cn.ConnectionString = conn
Cn.Open()
Try
Da.UpdateCommand.CommandText = sql
Da.UpdateCommand.ExecuteNonQuery()
Catch ex As OleDbException
Console.WriteLine(ex.ToString)
Finally
Cn.Close()
End Try

End Sub

End Class
[/code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top