Write string into image

Source: Internet
Author: User

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;
}
}

 

 

 

 

 

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.