The solution is simple enough: don't use
PictureBox
. This control is redundant, designed only for the simplest tasks (showing static images) and won't help you if you want something a bit more complex, such as zooming. It can only add you hassles, waste some extra resources and your development time. Please see my past answers and advise what to do instead:
Append a picture within picturebox[
^],
draw a rectangle in C#[
^],
How do I clear a panel from old drawing[
^].
Some other answers on graphics rendering:
What kind of playful method is Paint DataGridView,
Capture the drawing on a panel,
Drawing Lines between mdi child forms.
And this is my past answer related to zoom:
Zoom image in Csharp net mouse wheel.
Sorry that this answer has too many detail and repeated information. The essential new information is: using
Transform
and
Invalidate
. Alternatively, you can use the methods
System.Drawing.Graphics.DrawImage
which performs
re-sampling of the image, which happens where the method expects the size of the destination rectangle and this rectangle size is different from the image size. Please see:
System.Drawing.Graphics.DrawImage.
You will find the explanation on where to use drawing methods in my answers referenced above.
Now, a big warning for you: in re-sampling of the pixel images, only re-sampling down (when you render the image in smaller size) works well. At best, you can zoom the image in (to a bigger size) only slightly, otherwise you will get extremely poor quality. What to do: make you original image as big as possible so your re-sampling would mostly reduce the rendered image size. Also, as to the quality, you will need to leverage this property:
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.interpolationmode%28v=vs.110%29.aspx.
The best quality of rendering is the one you can obtain with
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
:
http://msdn.microsoft.com/en-us/library/system.drawing.drawing2d.interpolationmode%28v=vs.110%29.aspx.
—SA