惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hacker News: Front Page
A
About on SuperTechFans
腾讯CDC
罗磊的独立博客
博客园 - Franky
Last Week in AI
Last Week in AI
博客园_首页
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
L
LangChain Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recorded Future
Recorded Future
Vercel News
Vercel News
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
J
Java Code Geeks
有赞技术团队
有赞技术团队
V
V2EX
IT之家
IT之家
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
Jina AI
Jina AI
B
Blog RSS Feed
H
Help Net Security
N
Netflix TechBlog - Medium
Latest news
Latest news
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 司徒正美
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
C
Cisco Blogs
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
P
Proofpoint News Feed
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
News and Events Feed by Topic
T
Threatpost

博客园 - 群

DataGridView调整列宽及using()的用法 COM 对象与其基础 RCW 分开后就不能再使用 终于解决了一个问题--如何在数据绑定时不让combox控件触发SelectedIndexChanged事件 如何在winform中子窗体提交数据后刷新父窗体中的DataGRIDVIEW数据? 关于在.net中 预览上传控件中路径的图片 的方法 在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接)[转] 获取新插入的数据的自增ID 漂浮窗体的实现 取得当前日期所在的星期里从星期一到星期日所有的日期列表 触发器不能读『转』 Server.MapPath介绍 Server.MapPath介绍 .NET里面取2个时间相差的天数 在static方法中调用非静态方法? label分页 使用回车代替Tab键的功能代码 很不错的传值 设置ComboBox默认 动态生成图片热点
绘图(包括绘坐标,图片)
· 2007-05-14 · via 博客园 - 群

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              //制作人:陆永群  
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //获取上个页面传来的值
        ArrayList p = (ArrayList)Cache[Request.QueryString["param"]];     
        int intMapID = int.Parse(p[0].ToString());
        string strCoor = p[1].ToString();
        string[] str = strCoor.Split(',');
        //图片参数
        int iImageWidth = 0, iImageHeight = 0;                                   
        int iPosX, iPosY;

        //从数据库获取数据流
        string strConn;
        string strSQL;
        strConn = System.Configuration.ConfigurationManager.AppSettings["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);                     // 用数据流填充图片  并画出来
        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();                             //画坐标轴!
        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);                   //画外 上线
        p1.X = iImageWidth + 15;
        p1.Y = iImageHeight + 15;
        g.DrawLine(pen1, p2, p1);                   //画外 右线
        p2.X = 0;
        p2.Y = iImageHeight + 15;
        g.DrawLine(pen1, p1, p2);                   //画外 下线
        p1.X = 0;
        p1.Y = 0;
        g.DrawLine(pen1, p2, p1);                   //画外 左线

        p1.X = 15;
        p1.Y = 15;
        p2.X = iImageWidth + 15;
        p2.Y = 15;
        g.DrawLine(pen1, p1, p2);                   //画内
        p2.X = 15;
        p2.Y = iImageHeight + 15;
        g.DrawLine(pen1, p1, p2);                   //画内线
        //横标尺
        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;
        }

        //竖标尺
        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;
        }
        //为横坐标增加数字标示

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

        }
        //为纵坐标增加数字标示

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

        }
        //为图片增加数字表示
        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;
        }

        //画数据库原有的热点区域
        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;                   //取第一点
            p1.Y = int.Parse(str1[1]) + 15;
            int i = 2;
            while (i < str1.Length)                           //循环取出其他的点并连接起来。
            {

                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;                  //把图形封闭起来
            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 != "")                                      //画预览区域
        {
            pen1.Color = Color.Blue;
            p1.X = int.Parse(str[0])+15;                        //取第一点
            p1.Y = int.Parse(str[1])+15;
            int i = 2;
            while (i < str.Length)                              //循环取出其他的点并连接起来。
            {

                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;                       //把图形封闭起来
            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();                                               //完成


    }
}