Exemple #1
0
        private void btnPreview_Click(object sender, EventArgs e)
        {
            if (this.jsn != null)
            {
                this.jsn = null;
            }

            if (this.copyrightMode == CopyrightModeType.Individual)
            {
                this.jsn = CopyImage(this.txtPath.Text.Trim());
                if (this.jsn.PicData.Length > 0)
                {
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(this.jsn.PicData);
                    Bitmap bmp = new Bitmap(ms);
                    PreviewImage(bmp);
                }
                else
                {
                    MessageBox.Show("Select an image to watermark before clicking preview", "Missing Image", MessageBoxButtons.OK);
                }
            }
            else
            {
                // Get first image in list of images
                if (this.txtPath.Text.Trim().Length > 0)
                {
                    if (System.IO.Directory.Exists(this.txtPath.Text.Trim()))
                    {
                        if (GetFirstImageInFolder(this.txtPath.Text.Trim()).Length == 0)
                        {
                            // No images found
                            MessageBox.Show("Could not find any images in the folder you selected, please select another and try again.", "Missing Images", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            this.jsn = CopyImage(GetFirstImageInFolder(this.txtPath.Text.Trim()));
                            System.IO.MemoryStream ms = new System.IO.MemoryStream(this.jsn.PicData);
                            Bitmap bmp = new Bitmap(ms);
                            PreviewImage(bmp);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void LoadImage(string path)
        {
            if (this.jsn != null)
            {
                this.jsn = null;
            }

            this.jsn = CopyImage(path);

            if (this.jsn != null)
            {
                System.IO.MemoryStream ms = new System.IO.MemoryStream(this.jsn.PicData);
                Bitmap img = new Bitmap(ms);

                // 296 x 174
                int w = 296;
                int h = 174;
                if (img.Height > img.Width)
                {
                    w = Convert.ToInt32(img.Width / (double)img.Height * 174);
                    if (w > 296)
                    {
                        w = 296;
                    }
                }
                else
                {
                    h = Convert.ToInt32(img.Height / (double)img.Width * 296);
                    if (h > 174)
                    {
                        h = 174;
                    }
                }

                this.PictureBox1.Width  = w;
                this.PictureBox1.Height = h;

                this.PictureBox1.Image = img;
            }
        }
Exemple #3
0
        /// <summary>
        /// Copies the image from disk to memory
        /// </summary>
        /// <param name="path">Path of image to copy</param>
        private clsImage CopyImage(string path)
        {
            clsImage img = null;

            if (path.Trim().Length > 0)
            {
                System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Open);

                if (fs.CanRead)
                {
                    byte[] b = new byte[fs.Length + 1];
                    fs.Read(b, 0, (int)fs.Length);

                    img          = new clsImage();
                    img.PicData  = b;
                    img.FileName = fs.Name.Substring(fs.Name.LastIndexOf("\\") + 1);

                    System.IO.FileInfo fi = new System.IO.FileInfo(fs.Name);
                    fs.Close();

                    img.FileType = fi.Extension;

                    System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
                    Bitmap bmp = new Bitmap(ms);
                    ms.Close();

                    img.Height = bmp.Height;
                    img.Width  = bmp.Width;

                    bmp.Dispose();
                }
                else
                {
                    MessageBox.Show("Cannot read file, it might be locked", "Locked File", MessageBoxButtons.OK);
                }
            }

            return(img);
        }
Exemple #4
0
        private void ProcessFiles(string dir)
        {
            string[] str = System.IO.Directory.GetFiles(dir);
            foreach (string s in str)
            {
                if (this.jsn != null)
                {
                    this.jsn = null;
                }

                System.IO.FileInfo fi = new System.IO.FileInfo(s);

                if (this.fileTypes.Contains(fi.Extension.ToLowerInvariant()))
                {
                    this.jsn = CopyImage(s);
                    this.lblCurrentImage.Text = this.jsn.FileName;
                    System.IO.MemoryStream ms = new System.IO.MemoryStream(this.jsn.PicData);
                    Bitmap bmp = new Bitmap(ms);
                    this.PictureBox1.Image = bmp;
                    Application.DoEvents();
                    SaveImage(bmp, string.Concat(new[] { this.txtSavePath.Text.Trim(), "\\", this.currentDirectory, "\\", fi.Name }));
                }
            }
        }
Exemple #5
0
        private void btnStartProcessing_Click(object sender, EventArgs e)
        {
            if (this.jsn == null)
            {
                if (this.copyrightMode == CopyrightModeType.Individual)
                {
                    MessageBox.Show("Select an image before choosing the save button", "Missing Image", MessageBoxButtons.OK);
                    return;
                }
            }

            if (this.chkImageWatermark.Checked && this.lstWMImagePlacement.SelectedItem == null)
            {
                MessageBox.Show("Please select a watermark placement from the drop down list before continuing.", "Missing watermark placement", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (this.chkWatermark.Checked && this.lstWMTextPlacement.SelectedItem == null)
            {
                MessageBox.Show("Please select a watermark placement from the drop down list before continuing.", "Missing watermark placement", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (this.copyrightMode == CopyrightModeType.Individual)
            {
                if (this.jsn != null)
                {
                    this.jsn = null;
                }

                this.jsn = CopyImage(this.txtPath.Text.Trim());
                this.lblCurrentImage.Text = this.jsn.FileName;
                System.IO.MemoryStream ms = new System.IO.MemoryStream(this.jsn.PicData);
                Bitmap bmp = new Bitmap(ms);
                this.PictureBox1.Image = bmp;

                SaveImage(bmp, string.Concat(new[] { this.txtSavePath.Text.Trim(), "\\", this.jsn.FileName }));
                LoadImage(this.txtPath.Text.Trim());
                ProcessImage();
                MessageBox.Show("Image Data Saved", "Saved", MessageBoxButtons.OK);
            }
            else
            {
                if (System.IO.Directory.Exists(this.txtPath.Text.Trim()) == false)
                {
                    MessageBox.Show("Please locate the folder of images you would like to watermark", "Missing image path", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (System.IO.Directory.Exists(this.txtSavePath.Text) == false)
                {
                    MessageBox.Show("Please specify where you would like to save your watermarked images.", "Missing image path", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                this.imageCount = 0;

                // Get the count of images to process
                GetImageCountToProcess();
                this.lblImagesToProcess.Text = this.imageCount.ToString();

                // Process images in selected folder
                ProcessFiles(this.txtPath.Text.Trim());

                // Now process sub folders if user selected that option.
                if (this.chkSubDirectories.Checked)
                {
                    ProcessMultipleImages(this.txtPath.Text.Trim());
                }

                MessageBox.Show(this.fileCount + " image(s) watermarked", "Finished", MessageBoxButtons.OK);
            }
        }