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 DrawImage to map the corners of an image into a parallelogram in VB .NET
KeywordsDrawImage, copy picture, PaintPicture, VB.NET, map corners
CategoriesGraphics, VB.NET
 
Make a Bitmap object representing the source image. Make a destination Bitmap with the same dimensions. The example fills the destination Bitmap with a color so you can see where the mapped image finishes.

The program then makes an array of Point objects defining where the image's upper left, upper right, and lower left corners should be mapped. (VB determines where the fourth corner should be mapped to make the result a parallelogram.) The program then uses DrawImage to mape the image.

 
' Map the image's corners to a parallelogram.
Private Sub btnGo_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnGo.Click
    ' Get the Bitmaps and Graphics object.
    Dim fr_bm As New Bitmap(picImage.Image)
    Dim to_bm As New Bitmap(fr_bm.Width, fr_bm.Height)
    Dim gr As Graphics = Graphics.FromImage(to_bm)

    ' Fill the destination Bitmap with a background.
    gr.FillRectangle(Brushes.PapayaWhip, _
        to_bm.GetBounds(System.Drawing.GraphicsUnit.Pixel))

    ' Define the destination paralelogram.
    Dim dest_pts() As Point = { _
        New Point(150, 0), _
        New Point(fr_bm.Width, 50), _
        New Point(0, fr_bm.Height - 50) _
    }

    ' Draw the image.
    gr.DrawImage(fr_bm, dest_pts)

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