Ejemplo n.º 1
0
 public MyImageView(int width = 200, int height = 200)
 {
     this.width = width;
       this.height = height;
       image = new MyImage();
 }
Ejemplo n.º 2
0
        public MyForm()
        {
            Title  = "Simple image editor";
              Width  = 420;
              Height = 400;
              Background = System.Windows.Media.Brushes.Transparent;

              toolBar = new ToolBar();

              open = new Button();
              save = new Button();

              resize = new Button();

              incBright = new Button();
              decBright = new Button();

              incContrast = new Button();
              decContrast = new Button();

              flip90 = new Button();
              mirror = new Button();

              exit = new Button();

              open.Tag     = "Open";
              open.Content = "open";
              save.Tag     = "Save";
              save.Content = "save";

              resize.Tag     = "Resize";
              resize.Content = "resize";

              incBright.Tag     = "incBr";
              incBright.Content = "inc br";
              decBright.Tag     = "decBr";
              decBright.Content = "dec br";

              incContrast.Tag     = "incCon";
              incContrast.Content = "inc con";
              decContrast.Tag     = "decCon";
              decContrast.Content = "dec con";

              flip90.Tag     = "Flip90";
              flip90.Content = "flip";
              mirror.Tag     = "Mirror";
              mirror.Content = "mirror";

              exit.Tag     = "Exit";
              exit.Content = "exit";

              toolBar.Items.Add(open);
              toolBar.Items.Add(save);
              toolBar.Items.Add(new Separator());
              toolBar.Items.Add(resize);
              toolBar.Items.Add(incBright);
              toolBar.Items.Add(decBright);
              toolBar.Items.Add(incContrast);
              toolBar.Items.Add(decContrast);
              toolBar.Items.Add(flip90);
              toolBar.Items.Add(mirror);
              toolBar.Items.Add(new Separator());
              toolBar.Items.Add(exit);

              toolBar.Height = 32;
              toolBar.VerticalAlignment = VerticalAlignment.Top;
              this.AddChild(toolBar);

              foreach (var ctrl in toolBar.Items) {
            var btn = ctrl as Button;
            if (btn != null) {
              btn.Click += this.onClicked;
            }
              }

              imgView = new MyImageView(imgWidth, imgHeight);
              img = new MyImage("c:\\tmp\\f1.jpeg");

              Mouse.AddMouseUpHandler(this, onMouseUp);
              Mouse.AddMouseMoveHandler(this, onMouseMove);
              //this.MouseUp += new MouseEventHandler(onMouseUp);
              // MouseMove += new MouseEventHandler(onMouseMove);

              this.Show();
        }
Ejemplo n.º 3
0
        public MyForm()
        {
            Text = "Simple image editor";
              Size = new Size(420, 400);

              toolBar = new ToolBar();
              toolBar.Parent = this;

              open = new ToolBarButton();
              save = new ToolBarButton();

              resize = new ToolBarButton();

              incBright = new ToolBarButton();
              decBright = new ToolBarButton();

              incContrast = new ToolBarButton();
              decContrast = new ToolBarButton();

              flip90 = new ToolBarButton();
              mirror = new ToolBarButton();

              exit = new ToolBarButton();

              var spacer = new ToolBarButton();
              spacer.Style = ToolBarButtonStyle.Separator;

              open.Tag  = "Open";
              open.Text = "open";
              save.Tag  = "Save";
              save.Text = "save";

              resize.Tag  = "Resize";
              resize.Text = "resize";

              incBright.Tag  = "incBr";
              incBright.Text = "inc br";
              decBright.Tag  = "decBr";
              decBright.Text = "dec br";

              incContrast.Tag  = "incCon";
              incContrast.Text = "inc con";
              decContrast.Tag  = "decCon";
              decContrast.Text = "dec con";

              flip90.Tag  = "Flip90";
              flip90.Text = "flip";
              mirror.Tag  = "Mirror";
              mirror.Text = "mirror";

              exit.Tag  = "Exit";
              exit.Text = "exit";

              toolBar.ShowToolTips = true;
              toolBar.Buttons.AddRange(new ToolBarButton[] {open, save,
                                                    spacer,
                                                    resize,
                                                    incBright, decBright,
                                                    incContrast, decContrast,
                                                    flip90, mirror,
                                                    spacer,
                                                    exit});
              toolBar.ButtonClick += new ToolBarButtonClickEventHandler(onClicked);

              imgView = new MyImageView(imgWidth, imgHeight);
              img = new MyImage();

              Paint += new PaintEventHandler(onPaint);
              MouseUp += new MouseEventHandler(onMouseUp);
              MouseMove += new MouseEventHandler(onMouseMove);
        }
Ejemplo n.º 4
0
        void onClicked(object sender, RoutedEventArgs e)
        {
            var tag = (e.Source as Button).Tag;

              if (tag.Equals("Exit"))
            Close();
              else if (tag.Equals("Save")) {
            SaveFileDialog dialog = new SaveFileDialog();
            if (dialog.ShowDialog() == true) {
              img.saveAs(dialog.FileName);
            }
              } else if (tag.Equals("Open")) {
            OpenFileDialog dialog = new OpenFileDialog();
            if (dialog.ShowDialog() == true) {
              img = new MyImage(dialog.FileName);
            }
              } else if (tag.Equals("Resize")) {
            SizeBox sb = new SizeBox(img.width, img.height);
            if (sb.ShowDialog() == true) {
              img.resize(sb.width, sb.height);
              InvalidateVisual();
            }
              } else if (tag.Equals("incBr")) {
            img.changeBrightness(+5);
            InvalidateVisual();
              } else if (tag.Equals("decBr")) {
            img.changeBrightness(-5);
            InvalidateVisual();
              } else if (tag.Equals("incCon")) {
            img.changeContrast(+5);
            InvalidateVisual();
              } else if (tag.Equals("decCon")) {
            img.changeContrast(-5);
            InvalidateVisual();
              } else if (tag.Equals("Flip90")) {
            img.rotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
            InvalidateVisual();
              } else if (tag.Equals("Mirror")) {
            img.rotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);
            InvalidateVisual();
              }
        }
Ejemplo n.º 5
0
 void onClicked(object sender, ToolBarButtonClickEventArgs e)
 {
     if (e.Button.Tag.Equals("Exit"))
     Close();
       else if (e.Button.Tag.Equals("Save")) {
     SaveFileDialog dialog = new SaveFileDialog();
     if (dialog.ShowDialog(this) == DialogResult.OK) {
       img.saveAs(dialog.FileName);
     }
       } else if (e.Button.Tag.Equals("Open")) {
     OpenFileDialog dialog = new OpenFileDialog();
     if (dialog.ShowDialog(this) == DialogResult.OK) {
       img = new MyImage(dialog.FileName);
     }
       } else if (e.Button.Tag.Equals("Resize")) {
     SizeBox sb = new SizeBox(img.width, img.height);
     if (sb.ShowDialog(this) == DialogResult.OK) {
       img.resize(sb.width, sb.height);
       Refresh();
     }
       } else if (e.Button.Tag.Equals("incBr")) {
     img.changeBrightness(+5);
     Refresh();
       } else if (e.Button.Tag.Equals("decBr")) {
     img.changeBrightness(-5);
     Refresh();
       } else if (e.Button.Tag.Equals("incCon")) {
     img.changeContrast(+5);
     Refresh();
       } else if (e.Button.Tag.Equals("decCon")) {
     img.changeContrast(-5);
     Refresh();
       } else if (e.Button.Tag.Equals("Flip90")) {
     img.rotateFlip(RotateFlipType.Rotate90FlipNone);
     Refresh();
       } else if (e.Button.Tag.Equals("Mirror")) {
     img.rotateFlip(RotateFlipType.RotateNoneFlipY);
     Refresh();
       }
 }