Esempio n. 1
0
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("Save in new destination?", "Save", MessageBoxButtons.YesNoCancel);

            if (dr == DialogResult.Cancel)
            {
                return;
            }
            string strFolder = "";

            if (dr == DialogResult.Yes)
            {
                if (DialogResult.OK != FBD.Browse(out strFolder, true))
                {
                    strFolder = "";
                }
            }
            using (TabPage tp = SelectedTab)
            {
                PictureBox pb          = tp.PB();
                FileInfo   fi          = tp.FI();
                string     strFilename = strFolder != "" ? strFolder + "\\" + fi.Name : fi.FullName;
                pb.Image.Save(strFilename, ImageFormat.Jpeg);
                unmarkChanged(tp);
            }
        }
Esempio n. 2
0
 private void toolStripRotate_KeyUp(object sender, KeyEventArgs e)
 {
     toolStripRotate.Text = Regex.Replace(toolStripRotate.Text, "\\D", "");
     if (!string.IsNullOrEmpty(toolStripRotate.Text) && int.Parse(toolStripRotate.Text) > 0)
     {
         TabPage    tp  = SelectedTab;
         PictureBox pb  = tp.PB();
         FileInfo   fi  = tp.FI();
         Image      img = pb.Image;
         using (Graphics g = Graphics.FromImage(img))
         {
             // Set world transform of graphics object to translate.
             Point p = new Point(int.Parse(Math.Floor(float.Parse(img.Width.ToString()) / 2).ToString()), int.Parse(Math.Floor(float.Parse(img.Height.ToString()) / 2).ToString()));
             //g.RenderingOrigin = p;
             //g.TranslateTransform(p.X,p.Y);
             g.TranslateTransform(p.X * -1, p.Y);
             //g.FillRectangle(Brushes.White, 0, 0, 9000, 9000);
             g.RotateTransform(float.Parse(toolStripRotate.Text));
             g.DrawImage(img, 0, 0);
             //g.Save();
         }
         pb.Image = img;
         pb.Refresh();
         markChanged(tp);
     }
 }
Esempio n. 3
0
        private void cCWToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TabPage    tp = SelectedTab;
            PictureBox pb = tp.PB();

            pb.Image.RotateFlip(RotateFlipType.Rotate270FlipNone);
            pb.Refresh();
            markChanged(tp);
        }
Esempio n. 4
0
        private void resizeToolStripMenuItem_DropDownOpening(object sender, EventArgs e)
        {
            TabPage    tp = SelectedTab;
            PictureBox pb = tp.PB();

            if (pb == null)
            {
                return;
            }
            if (pb.Image == null)
            {
                pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
            }
            toolStripWidth.Text  = pb.Image.Width.ToString();
            toolStripHeight.Text = pb.Image.Height.ToString();
            markChanged(tp);
        }
Esempio n. 5
0
        private void toolStripWidth_KeyUp(object sender, KeyEventArgs e)
        {
            bool bPercent = toolStripWidth.Text.Contains("%");

            toolStripWidth.Text = Regex.Replace(toolStripWidth.Text, "\\D", "");
            if (!string.IsNullOrEmpty(toolStripWidth.Text) && int.Parse(toolStripWidth.Text) > 0)
            {
                TabPage    tp = SelectedTab;
                PictureBox pb = tp.PB();
                FileInfo   fi = tp.FI();
                if (uniformToolStripMenuItem.Checked)
                {
                    toolStripHeight.Text = Math.Floor(pb.Image.Height * (float.Parse(toolStripWidth.Text) / pb.Image.Width)).ToString();
                }
                if (int.Parse(toolStripHeight.Text) > 0)
                {
                    pb.Image = new Bitmap(Bitmap.FromFile(fi.FullName) as Image, new Size(int.Parse(toolStripWidth.Text), int.Parse(toolStripHeight.Text)));
                    markChanged(tp);
                }
            }
        }
Esempio n. 6
0
        private void ResizePicture(object state)
        {
            TabPage tp = state as TabPage;

            tp.Select();
            PictureBox pb = tp.PB();
            FileInfo   fi = tp.FI();

            System.GC.Collect();
            if (pb.Image == null)
            {
                pb.Image = new Bitmap(Bitmap.FromFile(fi.FullName) as Image);
            }
            this.Invoke((MethodInvoker) delegate
            {
                System.GC.Collect();
                pb.Image = new Bitmap(Bitmap.FromFile(fi.FullName) as Image, int.Parse(Math.Floor(pb.Image.Width * .5).ToString()), int.Parse(Math.Floor(pb.Image.Height * .5).ToString()));
                pb.Refresh();
                markChanged(tp);
                System.GC.Collect();
            });
        }
Esempio n. 7
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (bcropAll)
                {
                    TabPage    tp  = SelectedTab;
                    PictureBox pb  = tp.PB();
                    Bitmap     src = new Bitmap(pb.Image);
                    cropAllRect = pb.CR();
                    tabControl1.TabPages.Remove(SelectedTab);
                    icntlist = cropAllFiles.Count;
                    icnt     = 0;
                    foreach (var file in cropAllFiles)
                    {
                        ThreadPool.QueueUserWorkItem(CropAll, file);
                    }
                }
                else
                {
                    TabPage    tp       = SelectedTab;
                    PictureBox pb       = tp.PB();
                    Bitmap     src      = new Bitmap(pb.Image);
                    Rectangle  cropRect = pb.CR();
                    Bitmap     target   = new Bitmap(cropRect.Width, cropRect.Height);

                    using (Graphics g = Graphics.FromImage(target))
                    {
                        g.DrawImage(src, new Rectangle(0, 0, target.Width, target.Height), cropRect, GraphicsUnit.Pixel);
                        g.Save();
                    }
                    pb.Image = target;
                    pb.Refresh();
                }
            }
        }
Esempio n. 8
0
 public static FileInfo FI(this TabPage tp)
 {
     return((tp.PB().Tag as PBTAG).FI);
 }
Esempio n. 9
0
        private void cropAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.SelectedPath = getClipboardOrSelected();
            if (DialogResult.OK == fbd.ShowDialog())
            {
                icnt = 0;
                ThreadPool.SetMinThreads(1, 1);
                ThreadPool.SetMaxThreads(4, 4);
                SelectedPath = fbd.SelectedPath;
                cropAllFiles = Directory.EnumerateFiles(SelectedPath, "*.jpg", SearchOption.AllDirectories).ToList();
                icntlist     = cropAllFiles.Count();
                LoadFiles(cropAllFiles.Take(1).ToArray());

                bcropAll = true;

                TabPage    tp = SelectedTab;
                PictureBox pb = tp.PB();
                pb.ContextMenuStrip = null;
                pb.SizeMode         = PictureBoxSizeMode.StretchImage;
                if (pb.Image == null)
                {
                    pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
                }


                pb.MouseDown += (a, b) =>
                {
                    if (b.Button == MouseButtons.Right)
                    {
                        (pb.Tag as PBTAG).clipRect = new Rectangle();
                        pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
                    }
                };
                pb.MouseUp += (a, b) =>
                {
                    Rectangle clipRect = (pb.Tag as PBTAG).clipRect;
                    if (b.Button == MouseButtons.Left)
                    {
                        pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
                        float ratio = (float.Parse(pb.Image.Width.ToString()) / float.Parse(pb.Width.ToString()));

                        Graphics g = Graphics.FromImage(pb.Image);
                        g.ExcludeClip(clipRect);
                        Bitmap imgtr = new Bitmap(2, 2);
                        imgtr.SetPixel(0, 0, Color.Transparent);
                        imgtr.SetPixel(0, 1, Color.Silver);
                        imgtr.SetPixel(1, 0, Color.Silver);
                        imgtr.SetPixel(1, 1, Color.Transparent);
                        TextureBrush tb = new TextureBrush(imgtr);
                        g.FillRectangle(tb, new Rectangle(0, 0, pb.Image.Width, pb.Image.Height));
                        g.Save();

                        //foreach (string file in list.OrderBy(x => x))
                        //ThreadPool.QueueUserWorkItem(ResizeImage, file);
                    }
                };
                pb.MouseMove += (a, b) =>
                {
                    Rectangle clipRect = (pb.Tag as PBTAG).clipRect;
                    if (b.Button == MouseButtons.Left)
                    {
                        pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
                        float      ratiow = (float.Parse(pb.Image.Width.ToString()) / float.Parse(pb.Width.ToString()));
                        float      ratioh = (float.Parse(pb.Image.Height.ToString()) / float.Parse(pb.Height.ToString()));
                        PictureBox pbi    = a as PictureBox;
                        if (clipRect.Location.IsEmpty)
                        {
                            clipRect.Location = new Point(
                                int.Parse(Math.Floor(((b.X - pbi.Left) * ratiow)).ToString()),
                                int.Parse(Math.Floor(((b.Y - pbi.Top) * ratioh)).ToString())
                                );
                        }
                        clipRect.Size = new Size(
                            int.Parse(Math.Floor(((b.X - pbi.Left) * ratiow - clipRect.Location.X)).ToString()),
                            int.Parse(Math.Floor(((b.Y - pbi.Top) * ratioh - clipRect.Location.Y)).ToString())
                            );

                        Graphics g = Graphics.FromImage(pb.Image);

                        g.ExcludeClip(clipRect);
                        Bitmap imgtr = new Bitmap(2, 2);
                        imgtr.SetPixel(0, 0, Color.Transparent);
                        imgtr.SetPixel(0, 1, Color.Silver);
                        imgtr.SetPixel(1, 0, Color.Silver);
                        imgtr.SetPixel(1, 1, Color.Transparent);
                        TextureBrush tb = new TextureBrush(imgtr);
                        g.FillRectangle(tb, new Rectangle(0, 0, pb.Image.Width, pb.Image.Height));
                        g.Save();

                        pb.Refresh();

                        (pb.Tag as PBTAG).clipRect = clipRect;
                    }
                };
            }
        }
Esempio n. 10
0
        private void cropToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bcropAll = false;
            TabPage    tp = SelectedTab;
            PictureBox pb = tp.PB();

            pb.ContextMenuStrip = null;
            pb.SizeMode         = PictureBoxSizeMode.StretchImage;
            if (pb.Image == null)
            {
                pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
            }


            pb.MouseDown += (a, b) => {
                if (b.Button == MouseButtons.Right)
                {
                    (pb.Tag as PBTAG).clipRect = new Rectangle();
                    pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
                }
            };
            pb.MouseUp += (a, b) =>
            {
                Rectangle clipRect = (pb.Tag as PBTAG).clipRect;
                if (b.Button == MouseButtons.Left)
                {
                    pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
                    float ratio = (float.Parse(pb.Image.Width.ToString()) / float.Parse(pb.Width.ToString()));

                    Graphics g = Graphics.FromImage(pb.Image);
                    g.ExcludeClip(clipRect);
                    Bitmap imgtr = new Bitmap(2, 2);
                    imgtr.SetPixel(0, 0, Color.Transparent);
                    imgtr.SetPixel(0, 1, Color.Silver);
                    imgtr.SetPixel(1, 0, Color.Silver);
                    imgtr.SetPixel(1, 1, Color.Transparent);
                    TextureBrush tb = new TextureBrush(imgtr);
                    g.FillRectangle(tb, new Rectangle(0, 0, pb.Image.Width, pb.Image.Height));
                    g.Save();
                    //pb.Refresh();
                }
            };
            pb.MouseMove += (a, b) => {
                Rectangle clipRect = (pb.Tag as PBTAG).clipRect;
                if (b.Button == MouseButtons.Left)
                {
                    pb.Image = Bitmap.FromFile((pb.Tag as PBTAG).FI.FullName);
                    float      ratiow = (float.Parse(pb.Image.Width.ToString()) / float.Parse(pb.Width.ToString()));
                    float      ratioh = (float.Parse(pb.Image.Height.ToString()) / float.Parse(pb.Height.ToString()));
                    PictureBox pbi    = a as PictureBox;
                    if (clipRect.Location.IsEmpty)
                    {
                        clipRect.Location = new Point(
                            int.Parse(Math.Floor(((b.X - pbi.Left) * ratiow)).ToString()),
                            int.Parse(Math.Floor(((b.Y - pbi.Top) * ratioh)).ToString())
                            );
                    }
                    clipRect.Size = new Size(
                        int.Parse(Math.Floor(((b.X - pbi.Left) * ratiow - clipRect.Location.X)).ToString()),
                        int.Parse(Math.Floor(((b.Y - pbi.Top) * ratioh - clipRect.Location.Y)).ToString())
                        );

                    Graphics g = Graphics.FromImage(pb.Image);

                    g.ExcludeClip(clipRect);
                    Bitmap imgtr = new Bitmap(2, 2);
                    imgtr.SetPixel(0, 0, Color.Transparent);
                    imgtr.SetPixel(0, 1, Color.Silver);
                    imgtr.SetPixel(1, 0, Color.Silver);
                    imgtr.SetPixel(1, 1, Color.Transparent);
                    TextureBrush tb = new TextureBrush(imgtr);
                    g.FillRectangle(tb, new Rectangle(0, 0, pb.Image.Width, pb.Image.Height));
                    g.Save();

                    pb.Refresh();

                    (pb.Tag as PBTAG).clipRect = clipRect;
                }
            };
        }