六合开奖结果现场直播欢迎诸位!收藏本站注 册登 陆
常用三肖中特马:基础知识网络知识操作系统WPS网页制作数据库算法网页成功之路网络安全最新技术古典mid流行midmid背景下载中心
您现在的位置:首页 > 三肖中特马 > 文章页

利用ASP.NET实现在线截图的功能之ASP.NET代码

Admin | 2014-10-23 8:44:32 | ReadNums | 2048 | 标签 asp.net | 打印本页
     

  想实现ASP.NET实现在线截图的功能,需要使用两部分代码,请注意查看相应文章。

   这里是ASP.NET,JS代码在上篇。

  二、ASP.NET的代码

        string left = txt_left.Text;
        string top = txt_top.Text;
        string fileName = "";
        string Extension = "";
        int width=0;
        int height=0;
        DirectoryInfo path = new DirectoryInfo(Server.MapPath("~/Images"));
        foreach (FileInfo file in path.GetFiles())
        {
            if (file.Name.Substring(0,file.Name.IndexOf("."))=="Chrysanthemum")
            {
                Extension = file.Extension;
                fileName = Guid.NewGuid().ToString() + file.Extension;
                File.Copy(Server.MapPath("~/Images") + "/" + file.Name, Server.MapPath("~/Images") + "/" + fileName);
            }
        }
        if (fileName!="")
        {
            System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("~/Images") + "/" + fileName);
            width=image.Width;
            height=image.Height;
            int newWidth = 240 * width / (240 + 155);
            int newHeight = 180 * height / (180 + 115);
            int x = Convert.ToInt32(left) * width / (240 + 155);
            int y = Convert.ToInt32(top) * height / (180 + 115);
            Bitmap bmp = new Bitmap(newWidth, newHeight);
            Graphics graphics = Graphics.FromImage(bmp);
            Point[] destParal = new Point[] { new Point() { X = 0, Y = 0 }, new Point() { X = newWidth, Y = 0 }, new Point() { X = 0, Y = newHeight } };
            graphics.DrawImage(image, destParal, new Rectangle() { X = x, Y = y, Width = newWidth, Height = newHeight }, GraphicsUnit.Pixel);
            bmp.Save(Server.MapPath("~/Images")+"/"+ Guid.NewGuid().ToString() + Extension);
            graphics.Dispose();
            image.Dispose();
            File.Delete(Server.MapPath("~/Images") + "/" + fileName);
        }


问题未解决:在线咨询

网友评论

(访客)
内容实用原创,讲得很好。
20xx年x月x日
(站长)
有问题请在线咨询。
20xx年x月x日