Draw a cardinal spline
HowToDrawCardinalSpline.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,200);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.DarkSeaGreen);
Pen snowPen = new Pen(Color.Snow, 2);
Point p1 = new Point(40,50);
Point p2 = new Point(200,85);
Point p3 = new Point(255,30);
Point p4 = new Point(300,70);
Point p5 = new Point(350,25);
Point p6 = new Point(400,45);
Point p7 = new Point(435,35);
Point p8 = new Point(450,125);
Point[] pointsArray = { p1, p2, p3, p4, p5, p6, p7, p8 };
g.DrawCurve(snowPen,pointsArray);
//g.DrawCurve(Pen, Point());
String path = Server.MapPath("~/Image/DrawCurve.jpg");
bmp.Save(path,ImageFormat.Jpeg);
Image1.ImageUrl = "~/Image/DrawCurve.jpg";
g.Dispose();
bmp.Dispose();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net graphics - how to draw a cardinal spline (Graphics.DrawCurve Method)</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DodgerBlue; font-style:italic;">
How to draw a cardinal spline through a specified
<br /> array of Point structures in asp.net graphics
<br />Graphics.DrawCurve Method (Pen, Point())
</h2>
<hr width="500" align="left" color="DeepSkyBlue" />
<asp:Image
ID="Image1"
runat="server"
/>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="DrawCurve"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
