private void btn_Review_Click(object sender, EventArgs e) { string fullPath = GetTheFirstPic(); FileInfo file = new FileInfo(fullPath); FileStream fs = file.OpenRead(); Stream outputStream = new MemoryStream(); AddWaterMark.AddWatermark(fs, int.Parse(tbx_PX.Text), int.Parse(tbx_PY.Text), tbx_Text.Text, outputStream, listFont.SelectedItem.ToString(), Convert.ToInt32(cbx_Size.Text), (FontStyle)GetFontStyle(), btn_ChoosenColor.BackColor); pbx_After.Image = Image.FromStream(outputStream); fs.Close(); }
private void btn_Start2_Click(object sender, EventArgs e) { Image img = null; string path = tbx_Path2.Text; string fullPath = string.Empty; try { string[] imgExtension = { "*.jpg", "*.jpeg", ".gif", "*.bmp", "*.png" }; List <FileInfo> files = new List <FileInfo>(); DirectoryInfo dir = new DirectoryInfo(path); foreach (string ext in imgExtension) { FileInfo[] folder = dir.GetFiles(ext, SearchOption.AllDirectories); foreach (FileInfo file in folder) { FileStream fs = file.OpenRead(); fullPath = path + @"\" + file.Name; Stream outputStream = new MemoryStream(); AddWaterMark.AddWatermark(fs, int.Parse(tbx_PX.Text), int.Parse(tbx_PY.Text), tbx_Text.Text, outputStream, listFont.SelectedItem.ToString(), Convert.ToInt32(cbx_Size.Text), (FontStyle)GetFontStyle(), btn_ChoosenColor.BackColor); fs.Close(); img = Image.FromStream(outputStream); using (Bitmap savingImage = new Bitmap(img.Width, img.Height, img.PixelFormat)) { using (Graphics g = Graphics.FromImage(savingImage)) g.DrawImage(img, new Point(0, 0)); string[] t = file.Name.Split('.'); savingImage.Save(string.Concat(path, @"\", t[0], "_new.", t[1]), ImageFormat.Jpeg); } img.Dispose(); } } MessageBox.Show("Processing Completed", "Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("There was an error during processing...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (img != null) { img.Dispose(); } } }