The essence is simple. The picture is loaded into the picturebox, then at the touch of a button a watermark is added BUT! Now only the watermark and the watermark specified in the code are added, but it is necessary that the user himself can choose the picture and watermark he needs and all this with minimal code changes Actually, the code

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Imaging; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace FlipToFlip { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void openButton_Click(object sender, EventArgs e) //ΠžΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ { Bitmap image; //Bitmap для ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌΠΎΠ³ΠΎ изобраТСния { if (openFileDialog.ShowDialog() == DialogResult.OK) { textbox.Text = openFileDialog.FileName; } } { try { image = new Bitmap(openFileDialog.FileName); //Bitmap для ΠΎΡ‚ΠΊΡ€Ρ‹Π²Π°Π΅ΠΌΠΎΠΉ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ pictureBox1.Size = image.Size; //ΠšΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° подгоняСтся ΠΏΠΎΠ΄ Ρ€Π°Π·ΠΌΠ΅Ρ€ picturebox pictureBox1.Image = image; pictureBox1.Invalidate(); } catch { DialogResult result = MessageBox.Show("НСвозмоТно ΠΎΡ‚ΠΊΡ€Ρ‹Ρ‚ΡŒ Π²Ρ‹Π±Ρ€Π°Π½Π½Ρ‹ΠΉ Ρ„Π°ΠΉΠ»", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); //Если это НЕ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° } } } private void saveButton_Click(object sender, EventArgs e) //Π‘ΠΎΡ…Ρ€Π°Π½Π΅Π½ΠΈΠ΅ ΠΏΠΎΠ²Π΅Ρ€Π½ΡƒΡ‚ΠΎΠΉ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΈ { Bitmap pngSave = (Bitmap)pictureBox1.Image; SaveFileDialog sfd = new SaveFileDialog(); sfd.DefaultExt = "png"; sfd.Filter = "Image files (*.png;*jpg;*gif)|*.png; *jpg; *gif;|All files (*.*)|*.*"; if (sfd.ShowDialog() == DialogResult.OK) pngSave.Save(sfd.FileName, ImageFormat.Png); } private void watermark_Click(object sender, EventArgs e) { using (Image watermarkImage = image.FromFile(@"C:\Users\User\Desktop\14829270527610.png")) using (Graphics imageGraphics = Graphics.FromImage(image)) using (TextureBrush watermarkBrush = new TextureBrush(watermarkImage)) { int x = (image.Width / 2 - watermarkImage.Width / 2); int y = (image.Height / 2 - watermarkImage.Height / 2); watermarkBrush.TranslateTransform(x, y); imageGraphics.FillRectangle(watermarkBrush, new Rectangle(new Point(x, y), new Size(watermarkImage.Width + 1, watermarkImage.Height))); } } } } 
  • 2
    What is the question? Do it. - Daniel Protopopov
  • Those. How to load a picture in the pictureBox through OpenFileDialog you figure it out, but not with the same action for watermark? - Ev_Hyper

0