Creating Thumb Images

Public Function Generate_Thumb(ByVal GImage As Byte()) As Byte()
Dim Mstream As New System.IO.MemoryStream
Mstream.Write(GImage, 0, GImage.Length)
Dim BIMage As Bitmap
Dim Thumb As Bitmap
BIMage = Bitmap.FromStream(Mstream)
Thumb = CreateThumbNail(BIMage, 120, 120)
Dim imageStream As New System.IO.MemoryStream
Thumb.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim imageContent As Byte()
imageContent = imageStream.GetBuffer()
Return imageContent
End Function

‘---------------------------------------------------------

Private Function CreateThumbNail(ByVal postedFile As Bitmap, ByVal width As Integer, ByVal height As Integer) As Bitmap
Dim bmpOut As System.Drawing.Bitmap
Dim Ratio As Decimal
Dim NewWidth As Integer
Dim NewHeight As Integer
'*** If the image is smaller than a thumbnail just return it
If postedFile.Width < width AndAlso postedFile.Height < height Then
Return postedFile
End If
If (postedFile.Width > postedFile.Height) Then
Ratio = Convert.ToDecimal(width / postedFile.Width)
NewWidth = width

Dim Temp As Decimal = postedFile.Height * Ratio
NewHeight = Convert.ToInt32(Temp)
Else
Ratio = Convert.ToDecimal(height / postedFile.Height)
NewHeight = height

Dim Temp As Decimal = postedFile.Width * Ratio
NewWidth = Convert.ToInt32(Temp)
End If
bmpOut = New Bitmap(NewWidth, NewHeight)

Dim g As Graphics = Graphics.FromImage(bmpOut)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(Brushes.White, 0, 0, NewWidth, NewHeight)
g.DrawImage(postedFile, 0, 0, NewWidth, NewHeight)
postedFile.Dispose()
Return bmpOut
End Function