// --------------------------------------------------------------------------------------------------------------------------- Рисование графика по клику на мышку private void pictureBox3_MouseClick(object sender, MouseEventArgs e) { int w1 = pictureBox01.Image.Width; int h1 = pictureBox01.Image.Height; int[] bufr = new int[w1]; int[] bufyr = new int[h1]; int[] bufg = new int[w1]; int[] bufyg = new int[h1]; int[] bufb = new int[w1]; int[] bufyb = new int[h1]; Bitmap bmp1 = new Bitmap(pictureBox01.Image, w1, h1); Color c; int ii = 0; int s = (int)Math.Pow(2, count_scale); int x1 = X_MouseMove(e); int y1 = Y_MouseMove(e); int x = x1 * s; int y = y1 * s; label2.Text = "X:" + x.ToString(); label4.Text = "Y:" + y.ToString(); //MessageBox.Show(x.ToString() + " : " + y.ToString()); if (x1 >= w1 || y1 >= h1) { return; } // Point pnt = new Point(e.X, e.Y); if (reggrf == -1) // Маркер { c = bmp1.GetPixel(x1, y1); ii = c.R; label1.Text = "R:" + ii.ToString(); ii = c.G; label5.Text = "G:" + ii.ToString(); ii = c.B; label6.Text = "B:" + ii.ToString(); } if (reggrf == 1) // рисование графика { c = bmp1.GetPixel(x1, y1); ii = c.R; label1.Text = "R:" + ii.ToString(); ii = c.G; label5.Text = "G:" + ii.ToString(); ii = c.B; label6.Text = "B:" + ii.ToString(); for (int i = 0; i < w1; i++) { c = bmp1.GetPixel(i, y1); bufr[i] = c.R; bufg[i] = c.G; bufb[i] = c.B; } for (int i = 0; i < h1; i++) { c = bmp1.GetPixel(x1, i); bufyr[i] = c.R; bufyg[i] = c.G; bufyb[i] = c.B; } //Pen p = new Pen(Color.Red, 1); // GraphClass1.grfk(w1, h1, x, y, buf, bufy, p); Form fo = new GraphForm(x1, y1, w1, h1, bufr, bufyr, bufg, bufyg, bufb, bufyb); fo.Show(); fo.StartPosition = FormStartPosition.Manual; Point p = this.Location; p.Offset(840, 105); fo.Location = p; fo.Show(); // System.Windows.Forms.Cursor.Position = pnt; // Cursor.Show(); } Graphics line_cursor; Pen line_pen = new Pen(Color.Blue, 1); line_cursor = Graphics.FromHwndInternal(pictureBox01.Handle); if (reggrf == 0 && Cntr_end == 0) // Если включена кнопка область { if (x0_end != 0 || x1_end != 0 || y0_end != 0 || y1_end != 0) { pictureBox01.Refresh(); line_cursor.DrawRectangle(line_pen, x0_end / s, y0_end / s, (x1_end - x0_end) / s, (y1_end - y0_end) / s); } else { x0_end = x; y0_end = y; Cntr_end = -1; MessageBox.Show(" Левый верхний угол:" + x0_end.ToString() + " : " + y0_end.ToString()); } return; } if (reggrf == 0 && Cntr_end != 0) { x1_end = x; y1_end = y; Cntr_end = 0; MessageBox.Show(" Правый верхний угол:" + x1_end.ToString() + " : " + y1_end.ToString()); pictureBox01.Refresh(); line_cursor.DrawRectangle(line_pen, x0_end/s, y0_end/s, (x1_end - x0_end)/s, (y1_end - y0_end)/s); //line_cursor.DrawLine(line_pen, e.X, 0, e.X, pictureBox01.Height); } line_pen.Dispose(); line_cursor.Dispose(); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static void drawGraph(Image someImage, int pointX, int pointY, double ratio) { int w1 = someImage.Width; int h1 = someImage.Height; int[] bufr = new int[w1]; int[] bufyr = new int[h1]; int[] bufg = new int[w1]; int[] bufyg = new int[h1]; int[] bufb = new int[w1]; int[] bufyb = new int[h1]; Bitmap bmp1 = new Bitmap(someImage, w1, h1); Color c; if (pointX >= w1 || pointY >= h1) { return; } for (int i = 0; i < w1; i++) { c = bmp1.GetPixel(i, pointY); bufr[i] = (int) (c.R * ratio); bufg[i] = (int) (c.G * ratio); bufb[i] = (int) (c.B * ratio); } for (int i = 0; i < h1; i++) { c = bmp1.GetPixel(pointX, i); bufyr[i] = c.R; bufyg[i] = c.G; bufyb[i] = c.B; } Form fo = new GraphForm(pointX, pointY, w1, h1, bufr, bufyr, bufg, bufyg, bufb, bufyb); fo.Show(); fo.StartPosition = FormStartPosition.Manual; fo.Show(); }