First of all, you should not use
PictureBox
. My past answers explain why and what to do instead:
Append a picture within picturebox[
^],
draw a rectangle in C#[
^],
How do I clear a panel from old drawing[
^],
What kind of playful method is Paint? (DataGridViewImageCell.Paint(...))[
^],
capture the drawing on a panel[
^],
Drawing Lines between mdi child forms[
^].
Now, what is cropping? In view of the consideration discussed above, you don't have to create or modify a bitmap. You have a bitmap, but you should render only a part of it, but not
resample the original image. Look at the methods
System.Drawing.Graphics.DrawImage
:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage%28v=vs.110%29.aspx[
^].
First of all, you can have some control where you render of some smaller size. If you take negative origin of the image to be copied, it will be cropped on top or on left. Also, the part of the image beyond the control's client area will be cropped. It the cropping should occurs by the boundaries different from the whole client area, you need more parameters. The methods with one rectangle parameter will resample the image the the destination rectangle, so you should not use this method. However, the methods with two rectangle parameter (source and destination rectangles) may or may not resample the image. It won't resample it, apparently, when both rectangles are of the same exact size, so you only control the location of the smaller rectangle on the source image, and the place where you render it.
—SA