Add copyright information to the picture (C #) [Repost]

xiaoxiao2021-03-06  41

Nowadays, more websites like to add pictures uploaded by users to the website copyright information, don't think that it is to use the picture processing software such as Photoshop, in fact, we can implement this function as long as we write a small code. .

The principle of adding copyright information is actually quite simple: Get the object of the Graphics class through the image, which has a DrawString () method to write the information to the picture, even make a variety of effects, such as watermark, background transparency Wait. Finally, save the picture, you will have it.

We create a Windows application project, interface design is like

The code to add copyright information is as follows:

Code:

// create a bitmap Bitmap bitmap = new Bitmap (this.pictureBox2.Width, this.pictureBox2.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); // Get Canvas Graphics g = Graphics.FromImage bit map ( Bitmap); // Empty the canvas and populate G. Clear (Color.Transparent) with transparent colors; // draw another picture to the canvas on g.drawImage (this.picturebox1.image, 0); // write copyright Information onto the picture. g.drawstring (this.textbox2.text, new font ("black body", 15), new solidbrush (color.red), New Rectangle (20, 20, 100, 100)); // Shows this.PictureBox2.Image = bitmap; // Save Image Bitmap.Save ("C: //Abc.bmp", System.drawing.Image.imageFormat.BMP); By the way, click the "Select" button: Private Void Button1_Click (Object Sender, System.EventArgs e) {IF (this.openfiledialog1.showdialog () == DialogResult.ok) {if (this.openfiledialog1.filename.length == 0) {MessageBox.show ("please select Picture", "Error", MessageBoxButtons.ok , MessageBoxIcon.Error); return;} this.textBox1.Text = this.openFileDialog1.FileName; FileStream fs = new FileStream (this.openFileDialog1.FileName, FileMode.Open, FileAccess.Read); try {this.pictureBox1.Image = Image.fromstream (fs);} catch (exception) {messagebox.show ("Your Selected File is not recognizable picture format", "Error", MessageBoxButtons.ok, MessageBoxicon.Error);} finally {fs.close }}}

转载请注明原文地址:https://www.9cbs.com/read-69657.html

New Post(0)