' Declarations
Dim intWidth As Integer
Dim intHeight As Integer
Dim sizeMain As SizeF
Dim sizeNew As SizeF
Dim sizeNewThumb As SizeF
Dim fScale As Single
' New Bitmaps for modified images
Dim bmpNew As Bitmap
Dim bmpNewThumb As Bitmap
' Get Uploaded picture
Dim bmpMain As New Bitmap(filePicture.PostedFile.InputStream)
'Get the original size of the picture
sizeMain = New SizeF(bmpMain.Width / bmpMain.HorizontalResolution, bmpMain.Height / bmpMain.VerticalResolution)
' Create the Main Picture and save it
' Set the maximum picture width
intWidth = 200
intHeight = 200
'Always resize this image, to keep things constant
If CInt(sizeMain.Width) > intWidth Or CInt(sizeMain.Height) > intHeight Then
'Get scale at how to change image
fScale = Math.Min(intWidth / sizeMain.Width, intHeight / sizeMain.Height)
'Get new image size
sizeNew = New SizeF(sizeMain.Width, sizeMain.Height)
' Calculate the new height and width
sizeNew.Width *= fScale
sizeNew.Height *= fScale
'Get Thumbnail
bmpNew = bmpMain.GetThumbnailImage(CInt(sizeNewThumb.Width), CInt(sizeNewThumb.Height), Nothing, Nothing)
Else
bmpNew = bmpMain
End If
'Finally save the image
bmpNew.Save(ConfigurationSettings.AppSettings("ImageDataPath") & lblProductID.Text & "_TEMP.jpg", Drawing.Imaging.ImageFormat.Jpeg)
'Create the Thumbnail Image
'Set Thumbnail dimensions
intWidth = 75
intHeight = 75
'Always resize this image, to keep things constant
'Get scale at how to change image
fScale = Math.Min(intWidth / sizeMain.Width, intHeight / sizeMain.Height)
'Get new image size
sizeNewThumb = New SizeF(sizeMain.Width, sizeMain.Height)
' Calculate the new height and width
sizeNewThumb.Width *= fScale
sizeNewThumb.Height *= fScale
'Get Thumbnail
bmpNewThumb = bmpMain.GetThumbnailImage(CInt(sizeNewThumb.Width), CInt(sizeNewThumb.Height), Nothing, Nothing)
bmpNewThumb.Save(ConfigurationSettings.AppSettings("ImageDataPath") & lblProductID.Text & "_TEMP_THUMB.jpg", Drawing.Imaging.ImageFormat.Jpeg)