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.