在ASP.NET中上传图片并生成缩略图
private void btnUploadPicture_Click(object sender, System.EventArgs e)
{
//检查上传文件的格式是否有效
if(this.UploadFile.PostedFile.ContentType.ToLower().IndexOf("image") < 0)
{
Response.Write("上传图片格式无效!");
return;
}
//生成原图
Byte[] oFileByte = new byte[this.UploadFile.PostedFile.ContentLength];
System.IO.Stream oStream = this.UploadFile.PostedFile.InputStream;
System.Drawing.Image oImage = System.Drawing.Image.fromStream(oStream);
int oWidth = oImage.Width; //原图宽度
int oHeight = oImage.Height; //原图高度
int tWidth = 100; //设置缩略图初始宽度
int tHeight = 100; //设置缩略图初始高度
//按比例计算出缩略图的宽度和高度
if(oWidth >= oHeight)
{
tHeight = (int)Math.Floor(Convert.ToDouble(oHeight) * (Convert.ToDouble(tWidth) / Convert.ToDouble(oWidth)));
}
else
{
tWidth = (int)Math.Floor(Convert.ToDouble(oWidth) * (Convert.ToDouble(tHeight) / Convert.ToDouble(oHeight)));
}
//生成缩略原图
Bitmap tImage = new Bitmap(tWidth,tHeight);
Graphics g = Graphics.fromImage(tImage);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量插值法
g.SmoothingMode = System.Drawin
相关文档:
一.使用RegisterStartUpScript注册只执行一次的javascript
第1步(创建并注册并使用javascript):Page.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
//创建JavaScript
string info = "<mce:script type="text/javascript"><!--alert('你好,我是XXX!')// --></mce:scrip ......
因为用户的一些对象, 可能在config里进行配置, 但是config怎么能随便让你添加自己的节点呢! 不行你自己试试, 在任何位置添加任何没有申明的节点, 系统都不会让你通过, 更不会让你去读它了, 当然, 你打算在别的xml文件里添加节点, 然后读出来, 创建对象, 这个没问题. 为了系统能有组织的管理用户的在配置文件里的自定义信息 ......
ASP.NET页面间的传值的几种方法(转载)
ASP.NET WEB FORMS 给开发者提供了极好的事件驱动开发模式。然而这种简单的应用程序开发模式却给我们带来了一些小问题,举个例子,在传统的ASP应用程序中,你能够通过POST方法很容易的把一个值或多个值从一个页面传送到另一个页面,用同样的方法在ASP.NET中实现有点麻烦 ......
1.符号“/”指程序运行所在根目录,即IIs所在目录。
如果iis所在目录为:d:\programs
解决方案为d:\programs\d
网站路径为:d:\programs\d\web\
符号“/”代表的是:d:\programs,不管你的网站前面有多少级,都应该作为一个整体。
2.符号“~/”,则是指网站所在根目录。即d:\programs\ ......
引用命名空间
using System.Diagnostics;
string sPath = "d:\\test\\test.bat";
string sDict = "d:\\test\\";
ProcessStartInfo psi = new ProcessStartInfo("cmd.exe ......