Drawing Part of an Image

Nate Bross

Well-known member
Joined
Apr 6, 2005
Messages
601
Location
Chicago, IL
Hi, I have a bitmap, say its 800x600 pixels. I have a form that is fullscreen (1024x768), but I only want to draw a portian of the bitmap, say 400x400 pixels to the form. Any sugestions?

Code:
    Private Sub Form1_OnPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
        e.Graphics.DrawImage(BackBuffer, New Point(0, 0))
    End Sub

I would like to draw the top left region, 400x400 pixels out of 800x600 of BackBuffer onto the form.

I appreciate any advice you might have.
 
Bobs GDI+ faq has some help:
http://www.bobpowell.net/drawing_an_image.htm

Here is one of the overloads:
Code:
[Visual Basic]
Overloads Public Sub DrawImage( _
   ByVal image As Image, _
   ByVal destRect As Rectangle, _
   ByVal srcRect As Rectangle, _
   ByVal srcUnit As GraphicsUnit _
)
Use it like this:
Code:
Dim sourceRectangle As New Rectangle(0, 0, 400, 400) 
Dim targetRectangle As New Rectangle(0, 0, 400, 400) 
e.Graphics.DrawImage(backbuffer, targetRectangle, sourceRectangle, GraphicsUnit.Pixel)
 
Back
Top