Make a scribble application that lets the user zoom in or out on the picture in C#

// Draw the scaled picture on a Bitmap of the correct size.The code creates a bitmap at the appropriate size. The WorldWidth and WorldHeight constants determine how big the image is at full scale. The variable PictureScale gives the current scale as set by the ComboBox in the program's toolbar. Next the code creates a Graphics object to draw on the Bitmap. It clears the Bitmap, sets the SmoothingMode to give smooth drawing, uses the ScaleTransform method to scale the drawing, and then calls the following DrawImage method to draw the picture.
private void DrawPicture()
{
// Make a Bitmap of the right size.
Bitmap bm = new Bitmap(
(int)(PictureScale * WorldWidth),
(int)(PictureScale * WorldHeight));
// Make a Graphics object for the Bitmap.
// (If you need to use this later, you can give it
// class scope so you don't need to make a new one.)
using (Graphics gr = Graphics.FromImage(bm))
{
// Use a white background
// (so you can see where the picture is).
gr.Clear(Color.White);
// Draw smoothly.
gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
// Scale.
gr.ScaleTransform(PictureScale, PictureScale);
// Draw the image.
DrawImage(gr);
}
// Display the result.
picCanvas.Image = bm;
}
// Draw the Polylines on a Graphics object.The DrawImage method simply draws each of the program's Polylines on the Graphics object. This technique is simple and works well for up to several hundred points. With more complicated drawings, there is a noticeable delay when the user draws new curves. To solve this problem, the program needs a more efficient method for creating new curves. For example, it could save a copy of the current drawing and then display a new copy that also includes the curve the user is currently drawing. (I'll try to make such an example when I have time.) Download example
private void DrawImage(Graphics gr)
{
// Draw the polylines.
foreach (Polyline polyline in Polylines)
{
polyline.Draw(gr);
}
}
-->
Comments