C # Image Processing (6) -- add text

Source: Internet
Author: User

I personally think that adding text does not involve pixel processing. That is to say, it is not implemented using the same principle as in the previous four image processing examples. To add text, you can use the setting text Style dialog box that is frequently used to complete part of the text Style dialog box. Even if I paste the code, I will be more inspired to write things. I have begun to feel that I am incoherent.

To add text to an image, you must first enter the text you want to add in a TextBox Control, and then use a Button control to set the text style, the basic process is as follows.

 

Well, for a programmer, it is necessary to use a TextBox and a Button control to add similar code in the Button event,

FontDialog. ShowColor = true; // display color selection dialog box
If (this. fontDialog. ShowDialog () = DialogResult. OK)
{// After some font attributes are set
TextBox. Font = fontDialog. Font; // set the text Font.
TextBox. ForeColor = fontDialog. Color; // set the font Color of the text.

}

In this way, even if the font setting is complete, the text in the TextBox is the text of the style you set.

The following code is similar to the following,

/// <Summary>
/// Add text to the image
/// </Summary>
Private void pictureBox_MouseUp (object sender, MouseEventArgs e)
{

If (this. pictureBox. Image. Width <1)
{// Basic judgment is still required

Return;
}
Graphics gra = Graphics. FromImage (this. pictureBox. Image); // The Image object to be processed
SolidBrush brush = new SolidBrush (this. textBox. ForeColor); // initialize the paint brush
Gra. DrawString (this. textBox. Text, this. textBox. Font, brush, e. X, e. Y); // process the image
This. pictureBox. Refresh (); // Refresh the content in the container that displays the image to display the added text in time.
}

 

The principle is almost the same. These codes are part of the source code in my program, so they have not been tested, but there should be no problem. Apart from adding less namespaces, image processing code is usually used to add using System. drawing.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.