Write the string to the image.
1. line feed is implemented by specifying the write location
2. Be sure to release the resource. Otherwise, a win32error occurs.
Protected Void Page_load ( Object Sender, eventargs E)
{
If ( ! Ispostback)
{
// Parameters passed from the previous page
String Email = Request. querystring. Get ( " Email " );
String Realname = New Oluserservice. oluserservice (). getrealnamebyemail (email );
String Workid = New Oluserservice. oluserservice (). getworkidbyemail (email );
// Image1 image control-displays the image after the string is written.
String Filename = This . Image1.imageurl;
Int Index = Filename. lastindexof ( " . " );
String Newfilename = Filename. substring ( 0 , Index) + " _ " + Realname + Filename. substring (INDEX );
Fileinfo = New Fileinfo (server. mappath (filename ));
Fileinfo. copyto (server. mappath (newfilename ), True );
System. Drawing. Image = New Bitmap (server. mappath (newfilename ));
Graphics g = Graphics. fromimage (image );
String S2 = String . Format ( " Passed {0} of the Group Business Code of Conduct} " , Datetime. Now. tostring ( " Yyyy " ));
String S3 = " Annual certification. " ;
Font drawfont = New Font ( " Arial " , 12 );
Solidbrush drawbrush = New Solidbrush (color. Black );
// Supports line feed by specifying the write location
Drawpoint = New Pointf ( 50 , 200 );
G. drawstring (S2, drawfont, drawbrush, drawpoint );
drawpoint = New pointf ( 50 , 230 );
G. drawstring (S3, drawfont, drawbrush, drawpoint);
system. drawing. image IMG = New Bitmap (image );
// this is especially important. Resources are released after being used. otherwise, a Win32 error may occur.
// [externalexception (0x80004005): A generic error occurred in GDI +.]
G. dispose ();
image. dispose ();
IMG. Save (server. mappath (newfilename), system. Drawing. imaging. imageformat. JPEG );
This. Image1.imageurl=Newfilename;
}
}