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
 
 
 
 
 
TitleCopy one picture onto a location in another in VB .NET
KeywordsDrawImage, copy picture, PaintPicture, VB.NET
CategoriesGraphics, VB.NET
 
Make Bitmap objects representing the source and destination images. (Note that these Bitmap objects must be distinct.) Create a Graphics object attached to the destination Bitmap and use its DrawImage method to copy the picture.

This example then draws a rectangle around the copied picture. Notice how it uses a Rectangle object to define the rectangle and the destination for the copied image. Using the same Rectangle object ensures that the two match.

 
' Copy the entire picture into part of the picture.
Private Sub btnGo_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnGo.Click
    ' Note that fr_bm and to_bm must be different.
    Dim fr_bm As New Bitmap(picImage.Image)
    Dim to_bm As New Bitmap(picImage.Image)

    ' Get a Graphics object for fr_bm.
    Dim gr As Graphics = Graphics.FromImage(to_bm)

    ' Copy the image and a box around it.
    Dim rect As New Rectangle( _
        fr_bm.Width * 0.1, fr_bm.Height * 0.1, _
        fr_bm.Width * 0.4, fr_bm.Height * 0.4)
    gr.DrawImage(fr_bm, rect)
    gr.DrawRectangle(Pens.Red, rect)

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