在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
相关文档:
在Global.asax中导入命名空间
<%@Global ...
<%@Import Namespace= "System.Data " %>
<%@Import& ......
在ASP.NET中调用EXCEL组件的时候,如果没有配置DCOM中EXCEL权限问题,结果程序会报:Access is denied.
解决的方法有两种:
第一种,在web.config中设置一个节点.
<identity impersonate="true" />
不过这种方法只能解决local电脑上的Excel Access is denied的问题
如果是服务器的话,有客户机访问页面的时候, ......
Private static readonly object ReflectionLock = new object();
Lock (ReflectionLock)
{
Type scriptManagerType =
Type.GetType(
"System.Web.UI.ScriptManager, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35",
false);
......
因为用户的一些对象, 可能在config里进行配置, 但是config怎么能随便让你添加自己的节点呢! 不行你自己试试, 在任何位置添加任何没有申明的节点, 系统都不会让你通过, 更不会让你去读它了, 当然, 你打算在别的xml文件里添加节点, 然后读出来, 创建对象, 这个没问题. 为了系统能有组织的管理用户的在配置文件里的自定义信息 ......