(Remy Samulski)
12/22/2004 7:38:00 AM
I use the following code to create thumbnails and to enlarge images.
Public Shared Function ResizeBitmap( _
ByVal bmpBitmap As Bitmap, _
ByVal snglBoundingWidth As Single, _
ByVal snglBoundingHeight As Single, _
Optional ByVal blnHighQuality As Boolean = False) As Bitmap
Dim snglNewWidth, snglNewHeight As Single
If snglBoundingWidth > 1 And snglBoundingHeight > 1 Then
If (bmpBitmap.Height / bmpBitmap.Width) >
(snglBoundingHeight / snglBoundingWidth) Then
snglNewHeight = Int(snglBoundingHeight)
snglNewWidth = Int((bmpBitmap.Width / bmpBitmap.Height)
* snglNewHeight)
Else
snglNewWidth = Int(snglBoundingWidth)
snglNewHeight = Int((bmpBitmap.Height /
bmpBitmap.Width) * snglNewWidth)
End If
Else
snglNewWidth = bmpBitmap.Width * snglBoundingWidth
snglNewHeight = bmpBitmap.Height * snglBoundingHeight
End If
Dim bmpNewBitmap As System.Drawing.Bitmap
bmpNewBitmap = New Bitmap(bmpBitmap, snglNewWidth,
snglNewHeight)
If blnHighQuality = True Then
Dim g As Graphics = Graphics.FromImage(bmpNewBitmap)
g.InterpolationMode =
Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.DrawImage(bmpBitmap, 0, 0, bmpNewBitmap.Width,
bmpNewBitmap.Height)
End If
Return bmpNewBitmap
End Function