private void OnPictureBoxPaint(object sender, PaintEventArgs e) { Debug.WriteLine("OnPictureBoxPaint: Image=" + ((Image == null) ? "null" : Image.GetType().Name) + " LinesImage=" + ((LinesImage == null) ? "null" : LinesImage.GetType().Name) + " OverlayImage=" + ((OverlayImage == null) ? "null" : OverlayImage.GetType().Name)); if (Image == null) { return; } Graphics g = e.Graphics; g.Clear(pictureBox.BackColor); g.DrawImage(Image, pictureBox.ClientRectangle, ViewRectangle, GraphicsUnit.Pixel); if (LinesImage != null) { g.DrawImage(LinesImage, pictureBox.ClientRectangle, ViewRectangle, GraphicsUnit.Pixel); } // Handle EDIT mode if (ActiveMode == Mode.EDIT && OverlayImage != null) { g.DrawImage(OverlayImage, pictureBox.ClientRectangle, ViewRectangle, GraphicsUnit.Pixel); } }
/// <summary> /// Clears the Lines. /// </summary> public void clearLines() { endLine(); Lines.clear(); if (LinesImage != null) { LinesImage.Dispose(); } LinesImage = new Bitmap(Image.Width, Image.Height); cleanupEdit(); }
/// <summary> /// Sets the initial, unzoomed, origin at top left ViewRectangle. Uses /// the Current Image or loads a new one depending on replace. /// </summary> /// <param name="fileName">Name of an image file.</param> /// <param name="replace">Whether to load a new Image from the fileName.</param> private void resetImage(string fileName, bool replace) { if (replace) { if (Image != null) { Image.Dispose(); } Image = new Bitmap(fileName); if (LinesImage != null) { LinesImage.Dispose(); } LinesImage = new Bitmap(Image.Width, Image.Height); CurrentFileName = fileName; Text = Title + ": " + CurrentFileName; } ZoomFactor = 1.0F; Size clientSize = pictureBox.ClientSize; ViewRectangle = new RectangleF(0, 0, clientSize.Width, clientSize.Height); pictureBox.Invalidate(); }