private void btnCropAroundDragAndReleaseMouse_Click(object sender, EventArgs e) { try { if (modeRectangle == true) { modeRectangle = false; Rectangle rect = new Rectangle(startPoint, new Size(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y)); Image img = this.picOrigImage.Image; Bitmap bmp = new Bitmap(img); MyImageProc.CropImage(img, ref bmp, rect); picProcImage.Image = bmp; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } else { MessageBox.Show("you must click mouse to select bottom of rectangle"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnDrawX_Click(object sender, EventArgs e) { Image origimg = picOrigImage.Image; Bitmap bmp = new Bitmap(origimg); if (MyImageProc.DrawX(origimg, ref bmp, startPoint)) { picProcImage.Image = null; picProcImage.Image = bmp; } }
private void btnConvertToGray_Click(object sender, EventArgs e) { try { Bitmap copy = new Bitmap((Bitmap)this.picOrigImage.Image); MyImageProc.CovertToGray(copy); picProcImage.Image = null; picProcImage.Image = copy; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnResizeImage_Click(object sender, EventArgs e) { if (modeRectangle == true) { modeRectangle = false; Rectangle rect = new Rectangle(new Point(0, 0), new Size(endPoint.X, endPoint.Y)); Image img = this.picOrigImage.Image; Bitmap bmp = new Bitmap(img); MyImageProc.ResizeImage(img, ref bmp, rect); picProcImage.Image = bmp; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } else { MessageBox.Show("you must click mouse to select bottom of rectangle"); } }
private void btnShiftVertical_Click(object sender, EventArgs e) { FormShift dlg = new FormShift(); dlg.ShiftAmount = 0; Image origimg = picOrigImage.Image; Bitmap bmp = new Bitmap(origimg); if (DialogResult.OK == dlg.ShowDialog()) { if (MyImageProc.ShiftImageVertical(origimg, ref bmp, dlg.ShiftAmount)) { picProcImage.Image = null; picProcImage.Image = bmp; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } } }
private void btnRotateFill_Click(object sender, EventArgs e) { FormRotate dlg = new FormRotate(); dlg.RotationAngle = 0; Image origimg = picOrigImage.Image; Bitmap bmp = new Bitmap(origimg); if (DialogResult.OK == dlg.ShowDialog()) { if (MyImageProc.RotateFill(origimg, ref bmp, dlg.RotationAngle)) { picProcImage.Image = null; picProcImage.Image = bmp; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } } }
private void btnDraRectangle_Click(object sender, EventArgs e) { if (modeRectangle == true) { modeRectangle = false; Rectangle rect = new Rectangle(startPoint, new Size(endPoint.X - startPoint.X, endPoint.Y - startPoint.Y)); Image img = this.picOrigImage.Image; Bitmap bmp = new Bitmap(img); MyImageProc.DrawRectangle(img, ref bmp, rect); picProcImage.Image = bmp; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } else { MessageBox.Show("you must drag mouse to select rectangle"); } }
private void btnCropAroundMouseClick_Click(object sender, EventArgs e) { try { Image img = this.picOrigImage.Image; Bitmap bmp = new Bitmap(img); Point p1 = new Point(startPoint.X - int.Parse(txtCropAroundW.Text) / 2, startPoint.Y - int.Parse(txtCropAroundH.Text) / 2); Rectangle rect = new Rectangle(p1, new Size(int.Parse(txtCropAroundW.Text), int.Parse(txtCropAroundH.Text))); bmp = new Bitmap(img); MyImageProc.CropImage(img, ref bmp, rect); picProcImage.Image = bmp; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnRotateByPoints_Click(object sender, EventArgs e) { Image origimg = picOrigImage.Image; Bitmap bmp = new Bitmap(origimg); if (modeRectangle == true) { if (MyImageProc.RotateByPoints(origimg, ref bmp, startPoint, endPoint)) { picProcImage.Image = null; picProcImage.Image = bmp; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } } else { MessageBox.Show("you must click mouse to select bottom of rectangle"); } }
private void btnResizeProportional_Click(object sender, EventArgs e) { try { modeRectangle = false; int Width = int.Parse(txtNewSizeW.Text); int Height = int.Parse(txtNewSizeH.Text); Rectangle rect = new Rectangle(new Point(0, 0), new Size(Width, Height)); Image img = this.picOrigImage.Image; Bitmap bmp = new Bitmap(img); MyImageProc.ResizeImageProportional(img, ref bmp, rect); picProcImage.Image = bmp; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnChangeContrast_Click(object sender, EventArgs e) { try { FormContrast dlg = new FormContrast(); dlg.Contrast = 0; if (DialogResult.OK == dlg.ShowDialog()) { Bitmap copy = new Bitmap((Bitmap)this.picOrigImage.Image); copy = MyImageProc.Contrast(copy, (sbyte)dlg.Contrast); picProcImage.Image = null; picProcImage.Image = copy; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnBrightenImage_Click(object sender, EventArgs e) { try { FormBrightness dlg = new FormBrightness(); dlg.Brightness = 30; // default brightness of 30 if (DialogResult.OK == dlg.ShowDialog()) { Bitmap copy = new Bitmap((Bitmap)this.picOrigImage.Image); copy = MyImageProc.Brighten(copy, dlg.Brightness); picProcImage.Image = null; picProcImage.Image = copy; txtWidthProc.Text = picProcImage.Image.Width.ToString(); txtHeightProc.Text = picProcImage.Image.Height.ToString(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static bool RotateByPoints(Image img, ref Bitmap bm, Point p1, Point p2) { if ((p1.X == p2.X)) // no need to rotate { return(true); } Point midPt = new Point(); midPt.X = (int)((p1.X + p2.X) / 2.0); midPt.Y = (int)((p1.Y + p2.Y) / 2.0); double RotRadians = Math.Atan2(-(p2.Y - p1.Y), (p2.X - p1.X)); Point newmidPt = new Point(); newmidPt.X = (int)(midPt.X * Math.Cos(RotRadians) - midPt.Y * Math.Sin(RotRadians)); newmidPt.Y = (int)(midPt.Y * Math.Cos(RotRadians) + midPt.X * Math.Sin(RotRadians)); //MessageBox.Show(newmidPt.ToString()); double Rot = RotRadians * 180 / 3.141516; return(MyImageProc.RotateFill2(img, ref bm, Rot, midPt, newmidPt)); }