Click here to Skip to main content
15,887,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Bitmap ax = new Bitmap(300, 300);
Rectangle rc = new Rectangle(0, 0, 300, 300);
this.DrawToBitmap(ax, rc);
pictureBox1.Image = ax;


after running this code we have an image of part of form (from point(0,0) to point(300,300)) but i want an image from point(300,300) to point(600,600).
How I can do it?
Posted
Updated 13-Sep-11 21:31pm
v2

DrawToBitmap only draws from the TLHC of the source control, as it assumes that the whole control (in this case, probably an entire form) will be required. If you want just a portion, then you need to draw the whole control into a suitable bitmap, then draw a portion of that image into a new bitmap.
C#
Bitmap imageOfControl = new Bitmap(600, 600);
Rectangle rc = new Rectangle(0, 0, 600, 600);
this.DrawToBitmap(imageOfControl , rc);
Bitmap ax = new Bitmap(300,300);
using (Graphics g = Graphics.FromImage(ax))
   {
   g.DrawImage(imageOfControl, new Rectangle (300, 300, 300, 300), new Rectangle(0, 0, 300, 300), GraphicsUnit.Pixel);
   }
imageOfControl.Dispose();
pictureBox1.Image = ax;
 
Share this answer
 
pictureBox1 must be a control on the form. Try moving the picture box to an origin of (300, 300).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900