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

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
Recent Commits to openclaw:main
Recent Commits to openclaw:main
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
S
Secure Thoughts
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
B
Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
A
Arctic Wolf
T
The Exploit Database - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
AWS News Blog
AWS News Blog
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
Google Online Security Blog
Google Online Security Blog
T
Troy Hunt's Blog
I
InfoQ
L
LINUX DO - 热门话题
WordPress大学
WordPress大学
C
Cisco Blogs
G
GRAHAM CLULEY
The Register - Security
The Register - Security
A
About on SuperTechFans
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Schneier on Security
Schneier on Security
Project Zero
Project Zero
H
Hackread – Cybersecurity News, Data Breaches, AI and More
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
H
Hacker News: Front Page
小众软件
小众软件
雷峰网
雷峰网
The Hacker News
The Hacker News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Tor Project blog
博客园 - 聂微东
N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
The GitHub Blog
The GitHub Blog
腾讯CDC
P
Palo Alto Networks Blog
Scott Helme
Scott Helme

博客园 - 绯村剑心

日期对象ToString方法格式符的大小写对输出结果是有影响的 - 绯村剑心 - 博客园 Ajax基础配置 — XMLHttpRequest 让文本输入框只能输入数字 - 绯村剑心 - 博客园 抓取网页中的链接 检测客户端显示器分辨率、浏览器类型和客户端IP 在ASP.NET 中实现单点登录(利用Cache, 将用户信息保存在服务器缓存中) 对于长时间装载的ASP.NET页面如何在客户端浏览器中显示进度? 带图片的,多列的DropDownList的实现 - 绯村剑心 - 博客园 一个很不错介绍session的文章 无法从Web服务器获取项目文件 曼彻斯特码与差分曼彻斯特码 如何清除SQL server日志 sql server日志文件总结及日志满的处理办法 SQL SERVER 安装问题详解 Server实用操作小技巧集合 从html中提出纯文本 用JAVASCRIPT来刷新框架子页面的七种方法。 创建高度动态变化的Iframe ASP.NET程序中常用的三十三种代码
上传图片并生成缩略图
绯村剑心 · 2006-08-30 · via 博客园 - 绯村剑心

前台
<form id="Form1" method="post" runat="server" enctype="multipart/form-data">
                  <table id="Table1" cellpadding="1" cellspacing="1" width568 border="1">
                        <tr>
                              <td>
                                    <asp:Label ID="Label1" Runat="server">要上传的图片</asp:Label>
                              </td>
                              <td>
                                    <input id="upImage" type="file" name="File1" runat="server"></td>
                              <td><asp:Button ID="btnUp" Runat="server" Text="上传并生成缩图"></asp:Button></td>
                        </tr>
                        <tr>
                              <td><asp:Label ID="Label2" Runat="server">原图片</asp:Label></td>
                              <td align="center" colspan="2"><asp:Image ID="imageSource" Runat="server"></asp:Image>
                              </td>
                        </tr>
                        <tr>
                              <td><asp:Label ID="Label3" Runat="server">缩图</asp:Label></td>
                              <td align="center" colspan="2">
                                    <asp:Image ID="imageSmall" Runat="server"></asp:Image></td>
                        </tr>
                  </table>
            </form>
后台
public System.Drawing.Image image,newimage;//定义
         protected string imagePath;
  protected string imageType;
  protected string imageName;
  //提供一个回调方法,用于确定Image对象在执行生成缩图操作时河时提前取消执行
  //如果此方法确定GetThumbnailImage方法应该提前停此执行,返回true 否则返回false
  protected System.Drawing.Image.GetThumbnailImageAbort callb=null;
  private void btnUp_Click(object sender, System.EventArgs e)
  {
   string mPath;
   if(""!=upImage.PostedFile.FileName)
   {
    imagePath=upImage.PostedFile.FileName;
    //取的图片类型
    imageType=imagePath.Substring(imagePath.LastIndexOf(".")+1);
    //取得图片名称
    imageName=imagePath.Substring(imagePath.IndexOf("\\")+1);
    if("jpg"!=imageType&&"gif"!=imageType)
    {
     Response.Write("<script laguage='javascript'>alert('请选择jpg和gif图片');</script>");
     return;
    
    }
    else
    {
     try
     {   //建立虚拟路径
      mPath=Server.MapPath(upFile);
      //保存到虚拟目录
      upImage.PostedFile.SaveAs(mPath+"\\"+imageName);
      //显示原图片
      imageSource.ImageUrl="upFile"+imageName;
      //为上传的图片建立应用
      image=System.Drawing.Image.FromFile(mPath+"\\"+imageName);
      //生存缩图
      newimage=image.GetThumbnailImage(300,300,callb,new System.IntPtr());
      //把缩图保存到指定的虚拟路径
      newimage.Save(Server.MapPath("upFile")+"\\small"+imageName);
      //释放image对象占用的资源
      image.Dispose();
      newimage.Dispose();

      imageSmall.ImageUrl="upFile/"+"small"+imageName;
      this.Response.Write("上传成功");

     }
     catch
     {
      this.Response.Write(" 上传失败");
     }
    }
   }
  
  }