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

推荐订阅源

Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
IT之家
IT之家
MongoDB | Blog
MongoDB | Blog
博客园_首页
S
SegmentFault 最新的问题
H
Help Net Security
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
T
The Blog of Author Tim Ferriss
量子位
GbyAI
GbyAI
M
MIT News - Artificial intelligence
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
B
Blog
月光博客
月光博客
博客园 - 聂微东
Vercel News
Vercel News
罗磊的独立博客
腾讯CDC
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
A
Arctic Wolf
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale
L
Lohrmann on Cybersecurity
I
Intezer
小众软件
小众软件
T
The Exploit Database - CXSecurity.com
Jina AI
Jina AI
C
Check Point Blog
AWS News Blog
AWS News Blog
C
Cisco Blogs
Martin Fowler
Martin Fowler
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
宝玉的分享
宝玉的分享
S
Security Affairs
大猫的无限游戏
大猫的无限游戏
N
News and Events Feed by Topic
雷峰网
雷峰网
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Hacker News: Front Page
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
P
Proofpoint News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog

博客园 - 绯村剑心

日期对象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(" 上传失败");
     }
    }
   }
  
  }