Results 1 to 3 of 3

Thread: [RESOLVED] [2005] image upload as BLOB after resizing

  1. #1

    Thread Starter
    Hyperactive Member Ms.Longstocking's Avatar
    Join Date
    Oct 2006
    Posts
    399

    Resolved [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:
    1. Dim imageName As String = File1.PostedFile.FileName
    2.             Dim selectedFile As HttpPostedFile = File1.PostedFile
    3.             Dim imageLength As Integer = selectedFile.ContentLength
    4.             MsgBox(imageLength)
    5.             Dim binaryImagedata(imageLength) As Byte
    6.             selectedFile.InputStream.Read(binaryImagedata, 0, imageLength)
    7.  
    8.             Dim connStr As String = "connectionstring"
    9.             Dim connect As SqlConnection = New SqlConnection(connStr)
    10.             connect.Open()
    11.             Dim cmd As New SqlCommand("INSERT pic (id, avatar, imagename) VALUES (@id, @binaryimagedata, @imageName)", connect)
    12.             cmd.Parameters.AddWithValue("@id", id)
    13.             cmd.Parameters.AddWithValue("@binaryimagedata", binaryImagedata)
    14.             cmd.Parameters.AddWithValue("@imageName", imageName)
    15.                     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:
    1. selectedFile.InputStream.Read(binaryImagedata, 0, [COLOR=Red]imageLength[/COLOR])


    Here is the code used to convert the image size:

    VB Code:
    1. Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromFile(UploadedFile)
    2.         Dim dummyCallBack As System.Drawing.Image.GetThumbnailImageAbort = New System.Drawing.Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
    3.  
    4.         Dim ThumbHeight, ThumbWidth As Integer
    5.         Dim FullHeight As Integer = fullSizeImg.Height
    6.         Dim FullWidth As Integer = fullSizeImg.Width
    7.         If FullHeight > FullWidth Then
    8.             ThumbHeight = 64
    9.             ThumbWidth = FullWidth / FullHeight * 64
    10.         Else
    11.             ThumbWidth = 64
    12.             ThumbHeight = FullHeight / FullWidth * 64
    13.         End If
    14.         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.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member Ms.Longstocking's Avatar
    Join Date
    Oct 2006
    Posts
    399

    Re: [2005] image upload as BLOB after resizing

    Success:

    VB Code:
    1. Dim SelectedFile As HttpPostedFile = File1.PostedFile
    2. Dim imageLength As Integer = SelectedFile.ContentLength
    3. Dim imageType As String = SelectedFile.ContentType
    4. Dim imageStream As New System.IO.MemoryStream
    5. Dim binaryImagedata(imageLength) As Byte
    6. SelectedFile.InputStream.Read(binaryImagedata, 0, imageLength)
    7. Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromStream(New System.IO.MemoryStream(binaryImagedata))

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width