Get a portion of an image?

bonedoc

Well-known member
Joined
May 4, 2006
Messages
112
Programming Experience
Beginner
If I have a picturebox and want to capture the lower right quarter of it, what do I need to do? I cant seem to figure it out for the life of me. For some reason, I can only create an image that is a quarter of the size of the image, but it is always from (0,0).
VB.NET:
Dim r1 As New Rectangle(x2, y2, PictureBox1.Width / 2, PictureBox1.Width / 2)
                Dim b1 As New SolidBrush(Color.Black)
                g.FillRectangle(b1, PictureBox1.ClientRectangle)
                g.DrawImage(PictureBox1.Image, r1, PictureBox1.ClientRectangle, GraphicsUnit.Pixel)
 
You are now drawing to 'r1' rectangle from source rectangle full PictureBox1.ClientRectangle, so it scale the source to fit target.

You have to calculate the source rectangle to be drawn.
 
Back
Top