Wednesday, May 30, 2007

Resizing images/bitmaps the Visual Studio 2005 Way!

I've see so many ways to do this but this is so elegant it rocks. Here's how to resize an image in VB.NET 2005

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyImage As New Bitmap("D:\My Documents\My Pictures\untitled.bmp")
Dim MyThumbNail As Image
MyThumbNail = MyImage.GetThumbnailImage(MyImage.Width/2, MyImage.Hieght/2, AddressOf ThumbNailAbort, Nothing)
MyThumbNail.Save("D:\My Documents\My Pictures\Thumb.bmp")
End Sub

Private Function ThumbNailAbort() As Boolean
'Do Nothing Here
End Function

The delegate ThumbNailAbort is necessary, even if it is not yet implemented yet in .NET

No comments: