Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi, I have a bitmap, say it's 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?

 

   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.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

Bobs GDI+ faq has some help:

http://www.bobpowell.net/drawing_an_image.htm

 

Here is one of the overloads:

[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:

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)

Posted
Thanks man, I feel silly the overload was right there, I must have missed it. Thanks alot.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...