You can add text to images using the. NET program ~

Source: Internet
Author: User
1. implemented through the. NET built-in class library, Code As follows:

Image img = Image. fromfile ( @" E: \ aaa.bmp " );

System. Drawing. imaging. pixelformat _ pF = IMG. pixelformat;

/**/ /* Note: If the IMG image is indexed in pixel format, the following method will cause an exception
* For example:
* Pixelformat. format1bppindexed
* Pixelformat. format4bppindexed
* Pixelformat. format8bppindexed
* In addition, the following format also causes exceptions.
* Pixelformat. undefined
* Pixelformat. dontcare
* Pixelformat. format16bppargb1555
* Pixelformat. format16bppgrayscale
*/

Graphics gra = System. Drawing. Graphics. fromimage (IMG );

Font _ f =   New Font ( " " , 24 );
Solidbrush _ B =   New Solidbrush (color. Black );

Pen _ p =   New Pen (_ B, 10 );

Gra. drawstring ( " Blog " , _ F, _ B, 10 , 10 );
Gra. drawline (_ p, 1 , 1 , 100 , 100 );

Gra. Flush ();

Gra. Dispose ();

IMG. Save ( @" E: \ aaa2.bmp " );

2. Use Microsoft. office. document. imaging 11.0 Type Library. File Location: C: \ Program Files \ common files \ microsoft shared \ Modi \ mdivwctl. DLL

The Code is as follows: Using System;
Using Modi;
Namespace Addimg
{

Class Testaddimg
{
[Stathread]
Static   Void Main ( String [] ARGs)
{
Modi. Document Doc =   New Document ();
Doc. Create ( @" D: \ mytiff. tif " );
Doc. OCR (Modi. milanguages. milang_english, False , False );
Doc. Save ();
Modi. Image img = (Modi. Image) Doc. Images [ 0 ];
Console. writeline (IMG. layout. Text );
Console. Readline ();
}
}
}  

PS: both methods require the user to have operation permission on the image; otherwise, Access Denied is reported.

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.