zoukankan      html  css  js  c++  java
  • FileUpload上传图片直接浏览显示(没有上传按钮如何上传)

    1、给FileUpload添加一个onchange事件:FileUpload1.Attributes.Add("onchange", "document.getElementById('imgP').src=this.value");

    2、原来是单独的上传事件,现在没有上传按钮了,将上传的事件(代码)直接放入要执行的插入(提交信息)按钮事件中。

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
          if (IsValid)

          {

          //先执行上传事件

                string picName = "";
                string newpicName = "";
                string file = "/images/small/";
                string newPath = "/images/small/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "-" + DateTime.Now.Day + "/";
                UploadPicture.CreatDirectory(newPath);

                    ...........................

       

                   //此时也可以添加做好的水印

                picName = UploadInfo(fulImage, file);
                newpicName = UploadInfo(fulImage, newPath);

                System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(picName));
                System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath("/images/shuiyin.jpg"));
                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();
                //保存加水印过后的图片,删除原始图片
                image.Save(Server.MapPath(newpicName));
                image.Dispose();
                if (File.Exists(Server.MapPath(picName)))
                File.Delete(Server.MapPath(picName));

         }
    {

  • 相关阅读:
    Linux如何同步时间/更新时间
    Linux关机/重启/及注销命令
    Linux如何查看别名和取消别名
    Linux查看历史记录
    Linux命令行快捷键有哪些
    win10产品密钥 win10永久激活密钥(可激活win10所有版本 )
    Xshell如何连接
    Xshell6 优化
    逻辑运算符
    可变类型与不可变类型
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/4713587.html
Copyright © 2011-2022 走看看