//定义image类的对象
System.Drawing.Image image,newimage;
//图片路径
protected string imagePath;
//图片类型
protected string imageType;
//图片名称
protected string imageName;
//提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行
//如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false
System.Drawing.Image.GetThumbnailImageAbort callb = null;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 && "gif" != imageType)
{
Response.Write("<script language='javascript'> alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
return;
}
else
{
try
{
//建立虚拟路径
mPath=Server.MapPath("xq_image");
//保存到虚拟路径
upImage.PostedFile.SaveAs(mPath+"\\"+imageName);
//为上传的图片建立引用
image=System.Drawing.Image.FromFile(mPath+"\\"+imageName);
//生成缩略图
newimage=image.GetThumbnailImage(125,100,callb,new System.IntPtr());
//把缩略图保存到指定的虚拟路径
newimage.Save(Server.MapPath("xq_image")+"\\xq_"+imageName);
//释放image对象占用的资源
image.Dispose();
//释放newimage对象的资源
newimage.Dispose();
//显示缩略图
Image1.ImageUrl = "xq_image/"+"xq_"+imageName; Response.Write("<script language=javascript> alert('上传成功!');</script>");
}
catch(Exception ee)
{
Response.Write("<script language=javascript> alert('"+ee.Message+"');</script>");
}
}
}问题是可以生成缩略图,但是打不开,看到是一个大大的X
System.Drawing.Image image,newimage;
//图片路径
protected string imagePath;
//图片类型
protected string imageType;
//图片名称
protected string imageName;
//提供一个回调方法,用于确定Image对象在执行生成缩略图操作时何时提前取消执行
//如果此方法确定 GetThumbnailImage 方法应提前停止执行,则返回 true;否则返回 false
System.Drawing.Image.GetThumbnailImageAbort callb = null;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 && "gif" != imageType)
{
Response.Write("<script language='javascript'> alert('对不起!请您选择jpg或者gif格式的图片!');</script>");
return;
}
else
{
try
{
//建立虚拟路径
mPath=Server.MapPath("xq_image");
//保存到虚拟路径
upImage.PostedFile.SaveAs(mPath+"\\"+imageName);
//为上传的图片建立引用
image=System.Drawing.Image.FromFile(mPath+"\\"+imageName);
//生成缩略图
newimage=image.GetThumbnailImage(125,100,callb,new System.IntPtr());
//把缩略图保存到指定的虚拟路径
newimage.Save(Server.MapPath("xq_image")+"\\xq_"+imageName);
//释放image对象占用的资源
image.Dispose();
//释放newimage对象的资源
newimage.Dispose();
//显示缩略图
Image1.ImageUrl = "xq_image/"+"xq_"+imageName; Response.Write("<script language=javascript> alert('上传成功!');</script>");
}
catch(Exception ee)
{
Response.Write("<script language=javascript> alert('"+ee.Message+"');</script>");
}
}
}问题是可以生成缩略图,但是打不开,看到是一个大大的X
解决方案 »
- c#关于response.write script
- Server.Transfer传值
- ASPNET MVC新框架
- 如何下载文件夹内的word文件,文件名称存放在数据库中
- GetCookieHeader(new Uri(HttpReQuest.Url))和Headers["Set-Cookie"]的区别
- .com .biz .net .info.cn域名问题 顶者有分
- 异常详细信息: System.Data.OleDb.OleDbException: 操作必须使用一个可更新的查询。?什么原因
- 请教:帮忙读一下这个代码(50分)
- 求助,关于sql带入参数的写法问题。
- 共同讨论:关于OA系统文档管理部分的开发思路.(欢迎大家发言)
- CommandField 点击 Edit 按钮后 是执行哪个方法来使行中字段变成文本输入框的!
- GridView中删除数据出错问题!!!!!!!!!急急
//提取照片名及扩展名
string fullFileName =this.File1.PostedFile.FileName;
string fileName=fullFileName.Substring(fullFileName.LastIndexOf("\\")+1);
//取照片格式
string type=fullFileName.Substring(fullFileName.LastIndexOf(".")+1);
//验证照片格式
if(type=="jpg"||type=="bmp"||type=="gif"||type=="JPG"||type=="GIF")
{
this.File1.PostedFile.SaveAs(Server.MapPath("UpDownLoad")+"\\"+fileName);
this.Image1.ImageUrl="UpDownLoad/"+fileName;//显示照片
}
else
{
Response.Write("<script language='javascript'>alert('你选择的图片格式错误!');</script>");
}
kui1015(随风) ,我的代码和你的其实一样的