public ImagePart(IImagePart imagePart, int startRow, int startColumn, int width, int height) : this(width, height) { for (int currentRow = startRow, row = 0; currentRow < startRow + height; currentRow++, row++) { for (int currentCol = startColumn, col = 0; currentCol < startColumn + width; currentCol++) { this._colors[row, col++] = imagePart.GetColor(currentRow, currentCol); } } }
private void OnOpenButtonClick(object sender, EventArgs eventArgs) { if (this.openFileDialog.ShowDialog() == DialogResult.OK) { this.flowLayoutPanel.Controls.Clear(); this._pictureBox = new PictureBox { SizeMode = PictureBoxSizeMode.AutoSize, Margin = DefaultPadding, Image = new Bitmap(this.openFileDialog.FileName) }; bool selectionStarted = false; this._pictureBox.MouseDown += delegate(object o, MouseEventArgs args) { this._x = args.X; this._y = args.Y; selectionStarted = true; }; this._pictureBox.MouseUp += delegate(object o, MouseEventArgs args) { if (!selectionStarted) { return; } int x = 0, y = 0, width = 0, height = 0; if (args.X > this._x && args.Y > this._y) { x = this._x; y = this._y; width = args.X - x; height = args.Y - y; } else if (args.X > this._x && args.Y < this._y) { x = this._x; y = args.Y; width = args.X - x; height = this._y - y; } else if (args.X < this._x && args.Y > this._y) { x = args.X; y = this._y; width = this._x - x; height = args.Y - y; } else if (args.X < this._x && args.Y < this._y) { x = args.X; y = args.Y; width = this._x - x; height = this._y - y; } this._currentSelection = new ImagePart( this._imagePart, y, x, width, height ); selectionStarted = false; }; this._imagePart = new ImagePart(this._pictureBox.Image as Bitmap); this.flowLayoutPanel.Controls.Add(this._pictureBox); this._zIndex = 0; } }