Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse antialiasing to resize images smoothly in VB.NET
DescriptionThis example shows how to use antialiasing to resize images smoothly in VB.NET. This example demonstrates the Graphics object's InterpolationMode property.
Keywordsantialias, alias, image, resize, VB.NET
CategoriesGraphics, VB.NET
 
The form's Load event handler calls subroutine ShrinkImage to resize an image from one PictureBox to another. It then calls ShrinkImage again to resize the image with antialiasing.

Subroutine ShrinkImage makes a Bitmap to represent the input image. It then creates a new Bitmap that is half as tall and wide as the input image. If it should antialias, it sets the Graphics object's InterpolationMode property to HighQualityBilinear. It then uses the Graphics object's DrawImage method to copy the source Bitmap into the result Bitmap and displays the results.

 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    ShrinkImage(picOriginal, picNotAntialiased)
    ShrinkImage(picOriginal, picAntialiased, True)
End Sub

Private Sub ShrinkImage(ByVal from_pic As PictureBox, ByVal _
    to_pic As PictureBox, Optional ByVal anti_alias As _
    Boolean = False)
    ' Get the source Bitmap.
    Dim from_bm As New Bitmap(from_pic.Image)

    ' Make the destination Bitmap.
    Dim wid As Integer = from_pic.Width \ 2
    Dim hgt As Integer = from_pic.Height \ 2
    Dim to_bm As New Bitmap(wid, hgt)

    ' Copy the image.
    Dim gr As Graphics = Graphics.FromImage(to_bm)
    If anti_alias Then gr.InterpolationMode = _
        Drawing2D.InterpolationMode.HighQualityBilinear
    gr.DrawImage(from_bm, 0, 0, wid - 1, hgt - 1)

    ' Display the result.
    to_pic.Image = to_bm
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated