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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Upload Resize to Database

Status
Not open for further replies.

nidifice

Programmer
Oct 9, 2003
47
0
0
US
I had no problem uploading an image to MSSQL and then retrieving/displaying it.
Now I need to be able to resize it before I upload it. Here is what I currently have, but I can't get it to display after upload, so I'm sure I'm doing something wrong.

<code>
If Not filMyFile.PostedFile Is Nothing Then

' Get a reference to PostedFile object
Dim myFile As HttpPostedFile = filMyFile.PostedFile

Dim objImage As System.Drawing.Image = System.Drawing.Image.FromStream(myFile.InputStream)

Dim newImage As System.Drawing.Image = objImage.GetThumbnailImage(150, 150, Nothing, New System.IntPtr())

Dim io As New MemoryStream()
newImage.Save(io, System.Drawing.Imaging.ImageFormat.Jpeg)

' Get size of uploaded file
Dim nFileLen As Integer = io.Length

' make sure the size of the file is > 0
If nFileLen > 0 Then

' Allocate a buffer for reading of the file
Dim myData(nFileLen) As Byte

' Read uploaded file from the Stream
io.Read(myData, 0, nFileLen)

' Create a name for the file to store
Dim strFilename As String = Path.GetFileName(myFile.FileName)

' Store it in database
Dim nFileID As Integer = WriteToDB(strFilename, myFile.ContentType, myData)

' Set label's text
lblInfo.Font.Size = lblInfo.Font.Size.XXSmall
lblInfo.ForeColor = lblInfo.ForeColor.Green
lblInfo.Text = &quot;Filename: &quot; & strFilename & &quot;<br>&quot; & &quot;Size: &quot; & nFileLen.ToString() & &quot;<p>&quot;
lblInfo.Visible = True

imgDB.ToolTip = &quot;This file was stored in database.&quot;

' show the images and text
imgDB.ImageUrl = &quot;associatemonthpicture.aspx?FileID=&quot; + nFileID.ToString()
imgDB.Visible = True

End If
End If
</code>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top