/// <summary> /// Funkcja odpowiada za obsługe wycięcia zaznaczonego przez nas fragmentu /// </summary> private void PictureBox_MouseUp(object sender, MouseEventArgs e) { //Ustawiamy flage że mysz została puszczona bHaveMouse = false; if (rectCropArea.Width > 0 && rectCropArea.Height > 0) { //Jezeli rysowalismy rysujemy ponownie w tym miejscu zeby usunąć linie if (ptLast.X != -1) { Point ptCurrent = new Point(e.X, e.Y); } // Ustawiamy flagi jako info że nie ma poprzedniej lini do usunięcia ptLast.X = -1; ptLast.Y = -1; ptOriginal.X = -1; ptOriginal.Y = -1; Bitmap sourceBitmap = new Bitmap(((PictureBox)sender).Image, ((PictureBox)sender).Width, ((PictureBox)sender).Height); //Utworzenie bitmapy do ktorej zostanie zapisany wyciety przez nas fragment Bitmap croppedBitmap = new Bitmap(rectCropArea.Width, rectCropArea.Height); //Przerysowujemy zaznaczona czesc obrazu do nowej zmiennej using (Graphics g = Graphics.FromImage(croppedBitmap)) { g.DrawImage(sourceBitmap, new Rectangle(0, 0, croppedBitmap.Width, croppedBitmap.Height), rectCropArea, GraphicsUnit.Pixel); } sourceBitmap.Dispose(); int countWindows = 0; //Sprawdzamy ile aktualnie mamy okien o nazwie zaczynajacej sie od "Wycięty obraz" aby żadne wycięte okno się nie powtarzało foreach (var child in _main.MdiChildren) { if (child.Text.StartsWith("Wycięty obraz")) { countWindows++; } } //Tworzymy nowe okno z obrazem i histogramem z wycietego obrazu ImageWindow imageWindow = new ImageWindow(croppedBitmap, "Wycięty obraz" + countWindows, _main); imageWindow.MdiParent = _main; imageWindow.Show(); ((PictureBox)sender).Invalidate(); //Usuwamy stare zaznaczenie rectCropArea.Height = 0; rectCropArea.Width = 0; } }
private void acceptButton_Click(object sender, EventArgs e) { binaryOperation(((NamedImage)firstImageComboBox.SelectedItem).getImage(), ((NamedImage)secondImageComboBox.SelectedItem).getImage(), (OperationType)operationComboBox.SelectedItem); ImageWindow imageWindow = new ImageWindow(pictureBox1.Image, "Nowy Obraz"); imageWindow.MdiParent = mainWindow; imageWindow.Show(); Close(); }
private void PictureBox_MouseUp(object sender, MouseEventArgs e) { // Set internal flag to know we no longer "have the mouse". bHaveMouse = false; if (rectCropArea.Width > 0 && rectCropArea.Height > 0) { // If we have drawn previously, draw again in that spot // to remove the lines. if (ptLast.X != -1) { Point ptCurrent = new Point(e.X, e.Y); } // Set flags to know that there is no "previous" line to reverse. ptLast.X = -1; ptLast.Y = -1; ptOriginal.X = -1; ptOriginal.Y = -1; Bitmap sourceBitmap = new Bitmap(((PictureBox)sender).Image, ((PictureBox)sender).Width, ((PictureBox)sender).Height); Bitmap croppedBitmap = new Bitmap(rectCropArea.Width, rectCropArea.Height); using (Graphics g = Graphics.FromImage(croppedBitmap)) { g.DrawImage(sourceBitmap, new Rectangle(0, 0, croppedBitmap.Width, croppedBitmap.Height), rectCropArea, GraphicsUnit.Pixel); } //Good practice to dispose the System.Drawing objects when not in use. sourceBitmap.Dispose(); int countWindows = 0; foreach (var child in _main.MdiChildren) { if (child.Text.StartsWith("Wycięty obraz")) { countWindows++; } } ImageWindow imageWindow = new ImageWindow(croppedBitmap, "Wycięty obraz" + countWindows, _main); imageWindow.MdiParent = _main; imageWindow.Show(); ((PictureBox)sender).Invalidate(); rectCropArea.Height = 0; rectCropArea.Width = 0; } }
private void cloneWindowToolStripMenuItem_Click(object sender, EventArgs e) { int countWindows = 0; foreach (var child in MdiChildren) { if (child.Text.StartsWith(Path.GetFileName(openFileDialog1.FileName))) { countWindows++; } } ImageWindow activeImageWindow; if ((activeImageWindow = getSelectedImageWindow()) == null) { return; } ImageWindow imageCloneWindow = activeImageWindow.clone(activeImageWindow.FilePath + countWindows); imageCloneWindow.MdiParent = this; imageCloneWindow.Show(); }