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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Security Latest
Security Latest
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
V
V2EX
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tenable Blog
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
F
Full Disclosure
H
Help Net Security
博客园 - Franky
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
O
OpenAI News
S
Securelist

博客园 - MangaGo

在网页里让文本框只能输入数字的一种方法。外加回车换Tab - MangaGo - 博客园 (转) WINDOWS下的使用VS.NET2005的SVN手记 学习.Net的经典网站 Subversion快速入门教程 ASP.NET 2.0 下配置 FCKeditor - MangaGo asp中验证码图片为BMP格式,但是不显示 [Serializable]在C#中的作用-NET 中的对象序列化 VSS服务器安装配置 TimeSpan 用法 求离最近发表时间的函数 - MangaGo javascript判断密码安全级别 document.getElementById 你真正了解了吗 - MangaGo - 博客园 js获得当前日期并 显示 - MangaGo - 博客园 永远不要跟父母说的十句话,谁没说过? 用ASP.NET缓存提高站点性能【转载】 一个sql中常遇到的表结构转换问题 一个冒泡排序算法 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现 阶乘的经典算法! 关于上传文件的大小限制
在ASP.NET里轻松实现缩略图
MangaGo · 2007-12-26 · via 博客园 - MangaGo

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO; 
using System.Drawing.Imaging;

namespace eMeng.Exam
{
/// <summary>
/// Thumbnail 的摘要说明。
/// </summary>

public class Thumbnail : System.Web.UI.Page
{
    
protected System.Web.UI.WebControls.Label Label1;
    
protected System.Web.UI.WebControls.Button Button1;

    
private void Page_Load(object sender, System.EventArgs e)
    
{
        
// 在此处放置用户代码以初始化页面
        Label1.Text = "<h3>在ASP.NET里轻松实现缩略图</h3>"
        Button1.Text 
= "上载并显示缩略图"

    }


    
Web 窗体设计器生成的代码

    
private void Button1_Click(object sender, System.EventArgs e)
    
{
        HttpFileCollection MyFileColl 
= HttpContext.Current.Request.Files; 
        HttpPostedFile MyPostedFile 
= MyFileColl[0]; 

        
if (MyPostedFile.ContentType.ToString().ToLower().IndexOf("image"< 0
        

            Response.Write(
"无效的图形格式。"); 
            
return
        }
 
        GetThumbNail(MyPostedFile.FileName, 
100100
            MyPostedFile.ContentType.ToString(), 
false, MyPostedFile.InputStream); 
    }

    
private System.Drawing.Imaging.ImageFormat GetImageType(object strContentType) 
    

        
if ((strContentType.ToString().ToLower()) == "image/pjpeg"
        

            
return System.Drawing.Imaging.ImageFormat.Jpeg; 
        }
 
        
else if ((strContentType.ToString().ToLower()) == "image/gif"
        

            
return System.Drawing.Imaging.ImageFormat.Gif; 
        }
 
        
else if ((strContentType.ToString().ToLower()) == "image/bmp"
        

            
return System.Drawing.Imaging.ImageFormat.Bmp; 
        }
 
        
else if ((strContentType.ToString().ToLower()) == "image/tiff"
        

            
return System.Drawing.Imaging.ImageFormat.Tiff; 
        }
 
        
else if ((strContentType.ToString().ToLower()) == "image/x-icon"
        

            
return System.Drawing.Imaging.ImageFormat.Icon; 
        }
 
        
else if ((strContentType.ToString().ToLower()) == "image/x-png"
        

            
return System.Drawing.Imaging.ImageFormat.Png; 
        }
 
        
else if ((strContentType.ToString().ToLower()) == "image/x-emf"
        

            
return System.Drawing.Imaging.ImageFormat.Emf; 
        }
 
        
else if ((strContentType.ToString().ToLower()) == "image/x-exif"
        

            
return System.Drawing.Imaging.ImageFormat.Exif; 
        }
 
        
else if ((strContentType.ToString().ToLower()) == "image/x-wmf"
        

            
return System.Drawing.Imaging.ImageFormat.Wmf; 
        }
 
        
else 
        

            
return System.Drawing.Imaging.ImageFormat.MemoryBmp; 
        }
 
    }
 

    
private void GetThumbNail(string strFileName, int iWidth, int iheight, 
        
string strContentType, bool blnGetFromFile, System.IO.Stream ImgStream) 
    

        System.Drawing.Image oImg;
        
        
if (blnGetFromFile) 
        

            oImg 
= System.Drawing.Image.FromFile(strFileName); 
        }
 
        
else 
        

            oImg 
= System.Drawing.Image.FromStream(ImgStream); 
        }
 
        oImg 
= oImg.GetThumbnailImage(iWidth, iheight, null, IntPtr.Zero); 
        
string strGuid = System.Guid.NewGuid().ToString().ToUpper(); 
        
string strFileExt = strFileName.Substring(strFileName.LastIndexOf(".")); 
        Response.ContentType 
= strContentType; 
        MemoryStream MemStream 
= new MemoryStream(); 
        oImg.Save(MemStream, GetImageType(strContentType)); 
        MemStream.WriteTo(Response.OutputStream); 
    }
 

}

}