Ok, I have reviewed this code, and I assume it was written in C#. I converted it to VB, which is what I am using and I am trying to make sense of it. The club site is slightly different an that is why I think I am confused. The club site does not use store procedures as a part of the uploading of images. From what I can see everything is in the ImageHandling.vb file (as it relates to uploading and storing the file). Below is the code. What lines to I begin to look at changing to save the image to the file folder I specify and store the location in the location in the DB. Thanks for the help...
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Public Class ImageUtils
'Todo: Change this to use a database query through the middle tier
Public Shared Function uploadImage(ByVal title As String, ByVal albumid As Integer, ByVal data As IO.Stream) As Integer
Dim origImageData(CInt(data.Length - 1)) As Byte
data.Read(origImageData, 0, CInt(data.Length))
Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("ClubSiteDB").ConnectionString)
Dim command As New SqlCommand("INSERT INTO Images (title, origimage, largeimage, thumbimage, album) VALUES ( @title, @origimage, @largeimage, @thumbimage, @albumid); select SCOPE_IDENTITY()", connection)
Dim param0 As New SqlParameter("@title", System.Data.SqlDbType.VarChar, 50)
param0.Value = title
command.Parameters.Add(param0)
Dim param1 As New SqlParameter("@origimage", System.Data.SqlDbType.Image)
param1.Value = origImageData
command.Parameters.Add(param1)
Dim param2 As New SqlParameter("@largeimage", System.Data.SqlDbType.Image)
param2.Value = MakeThumb(origImageData, 350)
command.Parameters.Add(param2)
Dim param3 As New SqlParameter("@thumbimage", System.Data.SqlDbType.Image)
param3.Value = MakeThumb(origImageData, 69, 69)
command.Parameters.Add(param3)
Dim param4 As New SqlParameter("@albumid", System.Data.SqlDbType.Int)
param4.Value = albumid
command.Parameters.Add(param4)
connection.Open()
Dim result As Object = command.ExecuteScalar()
connection.Close()
If Not result Is Nothing Then
Return CInt(result)
Else
Return 0
End If
End Function
Const sizeThumb As Integer = 69
Public Shared Function MakeThumb(ByVal fullsize As Byte()) As Byte()
Dim iOriginal, iThumb As System.Drawing.Image
Dim targetH, targetW As Integer
' Grab Original Image
iOriginal = System.Drawing.Image.FromStream(New IO.MemoryStream(fullsize))
' Find Height and Width for Thumbnail Image
If (iOriginal.Height > iOriginal.Width) Then
targetH = sizeThumb
targetW = CInt(iOriginal.Width * (sizeThumb / iOriginal.Height))
Else
targetW = sizeThumb
targetH = CInt(iOriginal.Height * (sizeThumb / iOriginal.Width))
End If
iThumb = iOriginal.GetThumbnailImage(targetW, targetH, Nothing, System.IntPtr.Zero)
Dim m As New IO.MemoryStream()
iThumb.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg)
Return m.GetBuffer()
End Function
Public Shared Function MakeThumb(ByVal fullsize As Byte(), ByVal newwidth As Integer, ByVal newheight As Integer) As Byte()
Dim iOriginal, iThumb As System.Drawing.Image
Dim scaleH, scaleW As Double
Dim srcRect As Drawing.Rectangle
' Grab Original Image
iOriginal = System.Drawing.Image.FromStream(New IO.MemoryStream(fullsize))
' Find Height and Width for Thumbnail Image
scaleH = iOriginal.Height / newheight
scaleW = iOriginal.Width / newwidth
If scaleH = scaleW Then
srcRect.Width = iOriginal.Width
srcRect.Height = iOriginal.Height
srcRect.X = 0
srcRect.Y = 0
ElseIf (scaleH) > (scaleW) Then
srcRect.Width = iOriginal.Width
srcRect.Height = CInt(newheight * scaleW)
srcRect.X = 0
srcRect.Y = CInt((iOriginal.Height - srcRect.Height) / 2)
Else
srcRect.Width = CInt(newwidth * scaleH)
srcRect.Height = iOriginal.Height
srcRect.X = CInt((iOriginal.Width - srcRect.Width) / 2)
srcRect.Y = 0
End If
iThumb = New System.Drawing.Bitmap(newwidth, newheight)
Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(iThumb)
g.DrawImage(iOriginal, New Drawing.Rectangle(0, 0, newwidth, newheight), srcRect, Drawing.GraphicsUnit.Pixel)
Dim m As New IO.MemoryStream()
iThumb.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg)
Return m.GetBuffer()
End Function
Public Shared Function MakeThumb(ByVal fullsize As Byte(), ByVal maxwidth As Integer) As Byte()
Dim iOriginal, iThumb As System.Drawing.Image
Dim scale As Double
' Grab Original Image
iOriginal = System.Drawing.Image.FromStream(New IO.MemoryStream(fullsize))
If iOriginal.Width > maxwidth Then
scale = iOriginal.Width / maxwidth
Dim newheight As Integer = CInt(iOriginal.Height / scale)
iThumb = New System.Drawing.Bitmap(iOriginal, maxwidth, newheight)
Dim m As New IO.MemoryStream()
iThumb.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg)
Return m.GetBuffer()
Else
Return fullsize
End If
End Function
End Class
Shane L. Hackney