asp.net
/**////<summary>
Function: Write text to a picture
Date: 2006-11-20
Author: Yang Yixian
</summary>
<param name= "strFileName" > File name </param>
<param name= "strtext" > Text to write </param>
private void Texttoimage (String strfilename,string strtext)
{
if (! File.exists (MapPath (strFileName))
{
throw new FileNotFoundException ("file does not exist!");
}
if (strtext = = string. Empty)
{
Return
}
You also need to determine whether the file type is an image type
System.Drawing.Image Image = System.Drawing.Image.FromFile (MapPath (strFileName));
Bitmap Bitmap = new Bitmap (image,image. Width,image. Height);
Graphics grap = graphics.fromimage (bitmap);
float fontsize = 24.0f; Font size
float textWidth = strtext. Length*fontsize; Length of text
The following defines a rectangular area, in which the white and black characters are later painted in the rectangle.
float rectx = 0;
float recty = 0;
float rectwidth = strtext. length* (FONTSIZE+12);
float rectheight = fontsize+8;
String strfont;//define font type
Declaring a rectangular field
RectangleF TextArea = new RectangleF (rectx,recty,rectwidth,rectheight);
Strfont = Ddlfont. SelectedItem.Text.ToString (). Trim ();
Font font = new Font (strfont,fontsize); Defining fonts
Brush Whitebrush = new SolidBrush (color.white); White brush, painting text with
Brush Blackbrush = new SolidBrush (color.transparent); Black Brush, drawing background
Grap. FillRectangle (Blackbrush,rectx,recty,rectwidth,rectheight);
Grap. DrawString (Strtext,font,whitebrush,textarea);
MemoryStream ms = new MemoryStream ();
Save as JPG type
Bitmap. Save (Ms,imageformat.jpeg);
Output processed image.//Here you can enlarge the generated picture into Oracle database power
Response.Clear ();
Response.ContentType = "Image/jpeg";
Response.BinaryWrite (Ms. ToArray ());
Grap. Dispose ();
Bitmap. Dispose ();
Image. Dispose ();
}
Event:
private void Btnwrite_click (object sender, System.EventArgs e)
{
Httppostedfile Httppostfile; Client upload File Object
Httppostfile = Docupload.postedfile;
String strtemp;
String strfilename;//Completion file name
strtemp = HttpPostFile.FileName.ToString (). Trim ();
strFileName = Getrealfilename (strtemp);
String strimg = "images/";
Texttoimage (strimg +strfilename,txtdocname.text.tostring ());
}/**////<summary>
function: Get filename
Date: 2006-11-20
Author: Yang Yixian
</summary>
<param name= "strpathname" > File path </param>
<returns></returns>
public string Getrealfilename (string strpathname)
{
string [] strFileName = strpathname.split (' \ ');
int iPos = strfilename.getupperbound (0);
return Strfilename[ipos];
}