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))); } } } }
pictureBoxthroughOpenFileDialogyou figure it out, but not with the same action for watermark? - Ev_Hyper