Dzwebs.Net

撰写电脑技术杂文十余年

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

Admin | 2014-10-23 8:44:32 | 被阅次数 | 4079

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

  想实现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);
        }


该杂文来自: 网站开发杂文

上一篇:利用ASP.NET实现在线截图的功能之JS代码

下一篇:Microsoft.Office.Interop.Excel的代码收藏

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计