Graphics DrawString() Method
HowToDrawTextString.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Text" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Bitmap bmp = new Bitmap(500,150);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.DarkOrange);
String stringToDraw = ".net examples code";
Font drawFont = new Font("Courier New", 25);
SolidBrush brush = new SolidBrush(Color.Snow);
PointF drawPoint = new PointF(25, 25);
g.DrawString(stringToDraw,drawFont,brush,drawPoint);
//g.DrawString(String, Font, Brush, PointF);
String path = Server.MapPath("~/Image/DrawString.jpg");
bmp.Save(path,ImageFormat.Jpeg);
Image1.ImageUrl = "~/Image/DrawString.jpg";
g.Dispose();
bmp.Dispose();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net graphics (GDI+) - how to draw text string</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DodgerBlue; font-style:italic;">
How to draw the specified text string at the specified location
<br />with the specified Brush and Font objects in asp.net graphics (GDI+)
<br />Graphics.DrawString Method (String, Font, Brush, PointF)
</h2>
<hr width="575" align="left" color="DeepSkyBlue" />
<asp:Image
ID="Image1"
runat="server"
/>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="DrawString"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
- How to rotate an image
- How to draw an arc
- How to draw a rectangle
- How to draw a series of line segments
- How to draw a line connecting two Point structures
- How to draw a pie shape
- How to draw a polygon
- How to fill the interior of an ellipse
- How to measure the specified string
- How to set change pen color