Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Drawing;
Using System. IO;
Using System. Data. SqlClient;
Public partial class Image: System. Web. UI. Page // Producer: Lu yongqun
{
Protected void Page_Load (object sender, EventArgs e)
{
// Obtain the value from the previous page
ArrayList p = (ArrayList) Cache [Request. QueryString ["param"];
Int intMapID = int. Parse (p [0]. ToString ());
String strCoor = p [1]. ToString ();
String [] str = strCoor. Split (',');
// Image Parameters
Int iImageWidth = 0, iImageHeight = 0;
Int iPosX, iPosY;
// Obtain the data stream from the database
String strConn;
String strSQL;
StrConn = System. Configuration. ConfigurationManager. deleetpipeline ["MapConnectionString"];
SqlConnection sqlConn = new SqlConnection (strConn );
SqlConn. Open ();
StrSQL = "SELECT * FROM tMap WHERE MMapID = @ PMapID ";
SqlCommand sqlComm = new SqlCommand (strSQL, sqlConn );
SqlComm. Parameters. Add (new SqlParameter ("@ PMapID", SqlDbType. NVarChar ));
SqlComm. Parameters ["@ PMapID"]. Value = intMapID;
SqlDataReader sqlDR = sqlComm. ExecuteReader ();
MemoryStream ms1 = new MemoryStream ();
If (sqlDR. Read ())
{
Ms1 = new MemoryStream (byte []) sqlDR ["MMapData"]);
}
If (sqlDR! = Null) sqlDR. Close ();
If (sqlConn! = Null) sqlConn. Close ();
Bitmap bmTemp = new Bitmap (ms1); // fill the image with the data stream and draw it out.
IImageWidth = bmTemp. Width;
IImageHeight = bmTemp. Height;
Bitmap bmMain = new Bitmap (iImageWidth + 16, iImageHeight + 16 );
Graphics g = Graphics. FromImage (bmMain );
G. Clear (Color. White );
IPosX = 15;
IPosY = 15;
G. DrawImage (bmTemp, iPosX, iPosY, iImageWidth, iImageHeight );
BmTemp. Dispose ();
Point p1 = new Point (); // draw the Coordinate Axis!
Point p2 = new Point ();
Pen pen1 = new Pen (new SolidBrush (Color. FromArgb (0, 0, 0 )));
Pen1.Color = Color. Black;
P1.X = 0;
P1.Y = 0;
P2.X = iImageWidth + 15;
P2.Y = 0;
G. DrawLine (pen1, p1, p2); // publish the image offline
P1.X = iImageWidth + 15;
P1.Y = iImageHeight + 15;
G. DrawLine (pen1, p2, p1); // draw the outer right line
P2.X = 0;
P2.Y = iImageHeight + 15;
G. DrawLine (pen1, p1, p2); // get offline
P1.X = 0;
P1.Y = 0;
G. DrawLine (pen1, p2, p1); // draw the outer left line
P1.X = 15;
P1.Y = 15;
P2.X = iImageWidth + 15;
P2.Y = 15;
G. DrawLine (pen1, p1, p2); // inside the painting
P2.X = 15;
P2.Y = iImageHeight + 15;
G. DrawLine (pen1, p1, p2); // draw an internal line
// Horizontal ruler
Int intX = 15;
While (intX <= iImageWidth + 15)
{
P1.X = intX;
P1.Y = 10;
P2.X = intX;
P2.Y = 15;
If (intX-15) % 100 = 0)
{
P1.Y = 5;
P2.Y = iImageHeight + 15;
}
G. DrawLine (pen1, p1, p2 );
IntX = intX + 10;
}
// Vertical ruler
Int intY = 15;
While (intY <= iImageHeight + 15)
{
P1.X = 10;
P1.Y = intY;
P2.X = 15;
P2.Y = intY;
If (intY-15) % 100 = 0)
{
P1.X = 5;
P2.X = iImageWidth + 15;
}
G. DrawLine (pen1, p1, p2 );
IntY = intY + 10;
}
// Add a digital marker for the horizontal coordinate
IntX = 15;
Int drawInt = 0;
While (intX <= iImageWidth + 15)
{
If (intX-15) % 100 = 0)
{
DrawInt = intX-15;
String drawString = drawInt. ToString ();
SolidBrush drawBrush = new SolidBrush (Color. Black );
Font drawFont = new Font ("Arial", 7 );
IPosX = intX;
IPosY = 0;
G. DrawString (drawString, drawFont, drawBrush, iPosX, iPosY );
IntX = intX + 100;
}
}
// Add a numerical marker for the ordinate coordinates
IntY = 15;
DrawInt = 0;
While (intY <= iImageHeight + 15)
{
If (intY-15) % 100 = 0)
{
DrawInt = intY-15;
String drawString = drawInt. ToString ();
SolidBrush drawBrush = new SolidBrush (Color. Black );
Font drawFont = new Font ("Arial", 7 );
IPosX = 0;
IPosY = intY;
G. DrawString (drawString, drawFont, drawBrush, iPosX, iPosY );
IntY = intY + 100;
}
}
// Add a number to the image
Intx= 315;
IntY = 115;
DrawInt = 0;
Int drawInt1 = 0;
While (intY <= iImageHeight + 15)
{
While (intX <= iImageWidth + 15)
{
If (intY-15) % 100 = 0 & (intX-15) % 300 = 0)
{
DrawInt = intX-15;
DrawInt1 = intY-15;
String drawString = "(" + drawInt. ToString () + "," + drawInt1.ToString () + ")";
SolidBrush drawBrush = new SolidBrush (Color. Black );
Font drawFont = new Font ("Arial", 7 );
IPosX = intX;
IPosY = intY;
G. DrawString (drawString, drawFont, drawBrush, iPosX, iPosY );
}
IntX = intX + 300;
}
IntY = intY + 100;
Intx= 315;
}
// Draw the original hotspot area of the database
SqlConn. Open ();
StrSQL = "SELECT * FROM tArea WHERE MMapID = @ PMapID ";
SqlCommand sqlComm1 = new SqlCommand (strSQL, sqlConn );
SqlComm1.Parameters. Add (new SqlParameter ("@ PMapID", SqlDbType. NVarChar ));
SqlComm1.Parameters ["@ PMapID"]. Value = intMapID;
SqlDataReader sqlDR1 = sqlComm1.ExecuteReader ();
While (sqlDR1.Read ())
{
String strArea = sqlDR1 ["MCoords"]. ToString ();
String [] str1 = strArea. Split (',');
Pen1.Color = Color. Coral;
P1.X = int. Parse (str1 [0]) + 15; // obtain the first Vertex
P1.Y = int. Parse (str1 [1]) + 15;
Int I = 2;
While (I <str1.Length) // cyclically fetch other points and connect them.
{
P2.X = int. Parse (str1 [I]) + 15;
P2.Y = int. Parse (str1 [I + 1]) + 15;
G. DrawLine (pen1, p1, p2 );
P1.X = p2.X;
P1.Y = p2.Y;
I + = 2;
}
P1.X = int. Parse (str1 [0]) + 15; // close the graph.
P1.Y = int. Parse (str1 [1]) + 15;
P2.X = int. Parse (str1 [str1.Length-2]) + 15;
P2.Y = int. Parse (str1 [str1.Length-1]) + 15;
G. DrawLine (pen1, p1, p2 );
}
If (sqlDR! = Null) sqlDR. Close ();
If (sqlConn! = Null) sqlConn. Close ();
If (strCoor! = "") // Picture the preview area
{
Pen1.Color = Color. Blue;
P1.X = int. Parse (str [0]) + 15; // obtain the first Vertex
P1.Y = int. Parse (str [1]) + 15;
Int I = 2;
While (I <str. Length) // cyclically retrieve other points and connect them.
{
P2.X = int. Parse (str [I]) + 15;
P2.Y = int. Parse (str [I + 1]) + 15;
G. DrawLine (pen1, p1, p2 );
P1.X = p2.X;
P1.Y = p2.Y;
I + = 2;
}
P1.X = int. Parse (str [0]) + 15; // close the image
P1.Y = int. Parse (str [1]) + 15;
P2.X = int. Parse (str [str. Length-2]) + 15;
P2.Y = int. Parse (str [str. Length-1]) + 15;
G. DrawLine (pen1, p1, p2 );
}
BmMain. Save (Response. OutputStream, System. Drawing. Imaging. ImageFormat. Gif );
G. Dispose ();
BmMain. Dispose (); // complete
}
}