[RESOLVED] [2005] image upload as BLOB after resizing
Hello to all of the weather-weary out there!
User submits an image for uploading.
The system accepts the image and performs a resizing of the image to a standard 64x64.
I want to save the image as a BLOB. And under normal circumstances, I can do so without any issues with the following code:
VB Code:
Dim imageName As String = File1.PostedFile.FileName
Dim selectedFile As HttpPostedFile = File1.PostedFile
Dim imageLength As Integer = selectedFile.ContentLength
MsgBox(imageLength)
Dim binaryImagedata(imageLength) As Byte
selectedFile.InputStream.Read(binaryImagedata, 0, imageLength)
Dim connStr As String = "connectionstring"
Dim connect As SqlConnection = New SqlConnection(connStr)
connect.Open()
Dim cmd As New SqlCommand("INSERT pic (id, avatar, imagename) VALUES (@id, @binaryimagedata, @imageName)", connect)
cmd.Parameters.AddWithValue("@id", id)
cmd.Parameters.AddWithValue("@binaryimagedata", binaryImagedata)
cmd.Parameters.AddWithValue("@imageName", imageName)
cmdupass.ExecuteNonQuery()
However, after I resize the image, I have no way to extrapolate the bytesize of the new image. The byte size is needed for upload to occur.
VB Code:
selectedFile.InputStream.Read(binaryImagedata, 0, [COLOR=Red]imageLength[/COLOR])
Here is the code used to convert the image size:
VB Code:
Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromFile(UploadedFile)
Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
Dim ThumbHeight, ThumbWidth As Integer
Dim FullHeight As Integer = fullSizeImg.Height
Dim FullWidth As Integer = fullSizeImg.Width
If FullHeight > FullWidth Then
ThumbHeight = 64
ThumbWidth = FullWidth / FullHeight * 64
Else
ThumbWidth = 64
ThumbHeight = FullHeight / FullWidth * 64
End If
Dim thumbNailImg As System.Drawing.Image = fullSizeImg.GetThumbnailImage(ThumbWidth, ThumbHeight, dummyCallBack, IntPtr.Zero)
At this point I am stuck. I have a resized image but no way to upload to my db as a BLOB.
Re: [2005] image upload as BLOB after resizing
Once you've got the new Image object callits Save method to save it to a MemoryStream. Seek to the beginning of the Stream then call its Read method to get the data it contains into a Byte array. Assign the Byte array to your parameter's Value.
Re: [2005] image upload as BLOB after resizing
Success:
VB Code:
Dim SelectedFile As HttpPostedFile = File1.PostedFile
Dim imageLength As Integer = SelectedFile.ContentLength
Dim imageType As String = SelectedFile.ContentType
Dim imageStream As New System.IO.MemoryStream
Dim binaryImagedata(imageLength) As Byte
SelectedFile.InputStream.Read(binaryImagedata, 0, imageLength)
Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromStream(New System.IO.MemoryStream(binaryImagedata))