• 上传函数(全集)


            /// <summary>
            /// 文件上传,适用于.net2.0
            /// </summary>
            /// <param name="file">上传域FileUpload控件</param>
            /// <param name="SavePath">图片存储路径,默认为upload/</param>
      /// <param name="WatermarkImgFile">水印图片地址,留空则无水印</param>
            /// <returns>返回文件名</returns>
            public string FileUp(System.Web.UI.WebControls.FileUpload file,string SavePath, string WatermarkImgFile)
            {
                if (file.HasFile)
                {
                    string picName = file.PostedFile.FileName;
                    int pos = picName.LastIndexOf(".");
                    string excName = picName.Substring(pos);
                    kin.Web.CommTool commtool = new kin.Web.CommTool();
                    string newName = kin.Web.CommTool.RandomFileName() + excName;

        string phyicPath = HttpContext.Current.Server.MapPath(kin.Web.CommTool.GetAppPath + SavePath);
        //如果目录不存在,则创建
        if (Directory.Exists(phyicPath) == false)
                        Directory.CreateDirectory(phyicPath);
                    file.PostedFile.SaveAs(phyicPath + newName);

        if (WatermarkImgFile == "")
        {
                        //无水印,直接返回
                        return newName;
                    }

                    System.Drawing.Image image = System.Drawing.Image.FromFile(phyicPath + newName);
        //if (WatermarkType == 1)
        //{
         ////加文字水印,注意,这里的代码和以下加图片水印的代码不能共存
         //Graphics g = Graphics.FromImage(image);
         //g.DrawImage(image, 0, 0, image.Width, image.Height);
         //Font f = new Font("Verdana", 12);
         //Brush b = new SolidBrush(Color.White);
         //string addText = WatermarkString;
         //g.DrawString(addText, f, b, 10, 10);
         //g.Dispose();
        //}
        //else if (WatermarkType == 2) {
        //加图片水印
        System.Drawing.Image copyImage = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(kin.Web.CommTool.GetAppPath + WatermarkImgFile));
        Graphics g = Graphics.FromImage(image);
        g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width, image.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
        g.Dispose();
        //}

                    //保存加水印过后的图片,删除原始图片
                    string newName2 = kin.Web.CommTool.RandomFileName() + excName;
                    image.Save(phyicPath + newName2);
                    image.Dispose();
                    File.Delete(phyicPath + newName);
                    return newName2;
                }
                else
                {
                    return "";
                }
            }

  • 相关阅读:
    jdk动态代理
    HTML+JavaScript实现在一个下拉框中多选,然后提交到另外一个下拉框中的效果
    Top中是如何取到Linux内核中的Hertz的?以及CPU使用率到底是怎么算出来的?
    C语言中的负数是如何表示的?
    Learning Python第二版笔记-Chapter 3 How to run your program
    Learning Python第二版笔记-Chapter 4 Numbers
    Learning Python第二版笔记-Chapter 1 & 2
    Firefox中的document.all的替代方案From EasyCluster support Firefox
    Linux下共享库中的全局变量,静态变量是否只有一份?
    C和C++编程中static关键字的含义-修饰函数和变量
  • 原文地址:https://www.cnblogs.com/King0502/p/2019268.html
Copyright © 2020-2023  润新知