Here is a hint:
To copy a part of the image onto another image, use
System.Drawing.Graphics.DrawImage
:
https://msdn.microsoft.com/en-us/library/system.drawing.graphics.drawimage.aspx[
^].
Note that the methods which accept the target rectangle will perform
re-sampling of the image to be copied, if source and target rectangles sizes are different, which is a considerable performance hit; and the image quality may be compromised. Avoid them. Use, for, example, these methods instead:
https://msdn.microsoft.com/en-us/library/ms142038.aspx[
^],
https://msdn.microsoft.com/en-us/library/ms142039.aspx[
^].
To get an instance of
System.Drawing.Graphics
to draw on a bitmap, use
https://msdn.microsoft.com/en-us/library/system.drawing.graphics.fromimage(v=vs.110).aspx[
^].
You see, no
LockBits
or anything like that.
LockBits
is only needed if you have to manipulate at the level of bits, want to convert pixel types, things like that.
That's all.
And don't manipulate with
System.Windows.Forms.PictureBox
. Even if you want to use this purely redundant control type (which can be convenient in some simple cases), do all calculations with images, use
System.Drawing.Bitmap
as a target of your calculations, and, when they are done, assign this image to
PictureBox.Image
.