All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
visual c++ 中CFontDialog对话框实例
ASP.NET开发系列之在用户控件中添加事件_[Asp.Net教程]
利用同义词简化SQL Server 2005开发_[SQL Server教程]
安装Ms SQL Server 2005 开发版时出现性能计数器要求安装错误的解决办法_[SQL Server教程]
网页技巧:通过web.config设置数据库连接串_.net资料_编程技术
php中rename()函数的妙用_php资料_编程技术
创建复杂表头的表格_[Asp.Net教程]
SQL,Server日期计算_[SQL,Server教程]
SQL中的时间计算语句_[SQL,Server教程]
SQL循序渐进(21)更多的子查询_[SQL,Server教程]
Reading number is top 10 pictures
Exquisite decoration is not paying too much3
西游四格漫画(一)
photos of ashlynn brooke(ashlynn brooke的美图)
The money of more than 100 countries and regions5
超强高考作文
Azusa Yamamoto1
为什么别人说你是疯子
So beauty, will let you spray blood7
NeedWallpaper4
西游四格漫画(四)
Download software ranking
Tram sex maniac 2 (H) rar bag7
尖东毒玫瑰A
Unix video tutorial18
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
星际争霸1.08硬盘免安装版
功夫熊猫2(上集)
VC++6.0简体中文版
Twenty piece of palm leaf
徐若瑄成名作“魔鬼天使”
仙剑奇侠传98版歌曲
delv published in(发表于) 2014/1/24 9:04:00 Edit(编辑)
asp.net2.0按比例生成图片的缩略图_[Asp.Net教程]

asp.net2.0按比例生成图片的缩略图_[Asp.Net教程]

asp.net2.0按比例生成图片的缩略图_[Asp.Net教程]























1、建立Default.aspx文件和文件夹upFile

2、Default..aspx代码如下:









<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





无标题页






传图片:
onClick="btnUp_Click">

原图片:

缩略图:










3、Default..aspx.cs代码如下:









using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{

System.Drawing.Image image, newimage; //定义image类的对象
protected string imagePath;   //图片路径
protected string imageType;   //图片类型
protected string imageName;   //图片名称
//提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行
//如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false
System.Drawing.Image.GetThumbnailImageAbort callb = null;

protected void Page_Load(object sender, EventArgs e)
{

}
protected void btnUp_Click(object sender, EventArgs e)
{
string mPath;

if ("" != upImage.PostedFile.FileName)
{
imagePath = upImage.PostedFile.FileName;
//取得图片类型
imageType = imagePath.Substring(imagePath.LastIndexOf(".") + 1);
//取得图片名称
imageName = imagePath.Substring(imagePath.LastIndexOf("\") + 1);
//判断是否是JPG或者GIF图片,这里只是举个例子,并不一定必须是这两种图片
if ("JPG"!= imageType.ToUpper() && "GIF" != imageType.ToUpper())
{
Response.Write("");
return;
}
else
{
try
{
//建立虚拟路径
mPath = Server.MapPath("upFile");
//保存到虚拟路径
upImage.PostedFile.SaveAs(mPath + "\" + imageName);
//显示原图
imageSource.ImageUrl = "upFile/" + imageName;
//为上传的图片建立引用
image = System.Drawing.Image.FromFile(mPath + "\" + imageName);

int smallW = 100;//小图片宽
int smallH = smallW * image.Height / image.Width;//小图片高
//生成缩略图
newimage = image.GetThumbnailImage(smallW, smallH, callb, new System.IntPtr());
//把缩略图保存到指定的虚拟路径
newimage.Save(Server.MapPath("upFile") + "\small" + imageName);
//释放image对象占用的资源
image.Dispose();
//释放newimage对象的资源
newimage.Dispose();
//显示缩略图
imageSmall.ImageUrl = "upFile/" + "small" + imageName;
}
catch
{
Response.Write("上传失败!");
}

}
}
}
}







4:运行效果如下:













































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.