private void EditImage(Image image) { var editor = new SnapshotEditor(image); var changed = editor.ShowDialog(this); if (changed == DialogResult.OK) { image = editor.GetImage(); Helper.SetSizedImage(selectedPicture, image); } }
private void FitToImage() { //SendMessage(this.Handle, WM_SETREDRAW, false, 0); // suspend drawing on this form var screen = Screen.FromControl(this); var screenBounds = Screen.FromControl(this).Bounds; using (var temp = new SnapshotEditor(null)) { temp.Width = screenBounds.Width; temp.Height = screenBounds.Height; var img = pictureBoxSnapshot.Tag as Image; if (img != null) { var width = temp.pictureBoxSnapshot.Width - img.Width; var height = temp.pictureBoxSnapshot.Height - img.Height; if (width > 0) { this.Width = screenBounds.Width - width; } else { this.Width = screenBounds.Width - 50; } if (height > 0) { this.Height = screenBounds.Height - height; } else { this.Height = screenBounds.Height - 50; } if (width > 0 || height > 0) { WindowState = FormWindowState.Normal; var formRectangle = new Rectangle(this.Left, this.Top, this.Width, this.Height); if (!screen.WorkingArea.Contains(formRectangle)) { this.CenterToScreen(); } } } } //SendMessage(this.Handle, WM_SETREDRAW, true, 0); // suspend drawing on this form //this.Refresh(); }
private void pictureBox_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left && selecting && selection.Size != new Size()) { pictureBoxSnapshot.Cursor = Cursors.Default; cropping = false; selecting = false; // Redraw the picturebox: pictureBoxSnapshot.Refresh(); var zone = selection; if (zone.Width < 0) { zone = new Rectangle(zone.X + zone.Width, zone.Y, Math.Abs(zone.Width), zone.Height); } if (zone.Height < 0) { zone = new Rectangle(zone.X, zone.Y + zone.Height, zone.Width, Math.Abs(zone.Height)); } zone = new Rectangle((int)((double)zone.X * scale) + 1, (int)((double)zone.Y * scale) + 1, (int)((double)zone.Width * scale), (int)((double)zone.Height * scale)); // Create cropped image: Image img = pictureBoxSnapshot.Tag as Image; if (img != null) { img = img.Crop(zone); // preview to accept: var preview = new SnapshotEditor(img, true); var accept = preview.ShowDialog(this); if (accept == DialogResult.OK) { // Fit image to the picturebox: scale = Helper.SetSizedImage(pictureBoxSnapshot, img); originalImage = img; DisplayOriginalSize(); } } } else { selecting = false; } }